Skip to content

Commit

Permalink
Fix character case issues on definining documents directory for archive
Browse files Browse the repository at this point in the history
  • Loading branch information
jtellnes committed Feb 8, 2018
1 parent fbccdd6 commit 4d6bb3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions src/Arkivverket.Arkade/Core/Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,22 @@ public string GetInformationPackageFileName()

public DirectoryInfo GetDocumentsDirectory()
{
// Looks (once) for a document-directory with one of the names defined in DocumentDirectoryNames.
// If an actual directory is found, the field DocumentsDirectory is assigned with it and returned.
// If none is found, the field DocumentsDirectory is assigned with a new, non-existing directory
// given the name of the first element of DocumentDirectoryNames (should be the most common name).
// The method will always return a DirectoryInfo object in which can be checked by it's Exists-field.
if (DocumentsDirectory != null)
return DocumentsDirectory;

if (DocumentsDirectory == null)
{
int index = ArkadeConstants.DocumentDirectoryNames.Length - 1;
foreach (DirectoryInfo directory in WorkingDirectory.Content().DirectoryInfo().EnumerateDirectories())
foreach (string documentDirectoryName in ArkadeConstants.DocumentDirectoryNames)
if (directory.Name.Equals(documentDirectoryName))
DocumentsDirectory = directory;

do DocumentsDirectory = WorkingDirectory.Content().WithSubDirectory(
ArkadeConstants.DocumentDirectoryNames[index--]
).DirectoryInfo();

while (index >= 0 && !DocumentsDirectory.Exists);
}
return DocumentsDirectory ?? DefaultNamedDocumentsDirectory();
}

return DocumentsDirectory;
private DirectoryInfo DefaultNamedDocumentsDirectory()
{
return WorkingDirectory.Content().WithSubDirectory(
ArkadeConstants.DocumentDirectoryNames[0]
).DirectoryInfo();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Arkivverket.Arkade/Util/ArkadeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public class ArkadeConstants
public const string DirectoryNameAppDataArkadeSubFolder = "Arkivverket";

public static readonly string[] DocumentDirectoryNames =
{ "DOKUMENT", "DOKUMENTER", "dokument", "dokumenter" };
{ "dokumenter", "DOKUMENTER", "dokument", "DOKUMENT" };
}
}

0 comments on commit 4d6bb3d

Please sign in to comment.