Skip to content

Commit

Permalink
Store all configuration settings in MediaOrganizer.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
RiJo committed Dec 19, 2014
1 parent cecb455 commit 89bb6e4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
28 changes: 28 additions & 0 deletions MediaOrganizer/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,33 @@ public static string ReplaceInvalidPathChars(this string path, char replacement
path = path.Replace(invalidChar, replacement);
return path;
}

public static bool ToBool(this object value)
{
if (value == null)
throw new ArgumentNullException("value");

string s = value.ToString().ToLower();
return !(s == "0" || s == "false");
}

public static T ToEnum<T>(this object value) where T: struct
{
if (value == null)
throw new ArgumentNullException("value");

string s = value.ToString();
long i;
if (long.TryParse(s, out i))
{
// Interpret as numeric enum value
return (T)(object)i;
}
else
{
// Interpret as string enum name
return (T)Enum.Parse(typeof(T), s);
}
}
}
}
33 changes: 30 additions & 3 deletions MediaOrganizer/MediaOrganizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private enum GroupType
public CopyMode CopyMode = CopyMode.KeepUnique;
public ExceptionHandling ExceptionHandling = ExceptionHandling.Throw;
public bool VerifyFiles = true;
public string[] IgnorePaths = null;
public string[] IgnorePaths = null; // TODO: implement

private readonly Dictionary<string, GroupType> organizeGroups = new Dictionary<string, GroupType>()
{
Expand Down Expand Up @@ -149,7 +149,7 @@ public void LoadConfig() {
string iniFilePath = IniConfigFileName;

if (!File.Exists(iniFilePath))
SaveConfig();
SaveConfig(); // Generate default config file

IniFile iniFile = new IniFile();
iniFile.TryLoad(iniFilePath);
Expand All @@ -159,7 +159,25 @@ public void LoadConfig() {
if (iniFile.ContainsKey("destinationPath"))
destinationPath = iniFile["destinationPath"];
if (iniFile.ContainsKey("recursive"))
Recursive = iniFile["recursive"] == "1";
Recursive = iniFile["recursive"].ToBool();
if (iniFile.ContainsKey("locale"))
Localization = new CultureInfo(iniFile["locale"]);
if (iniFile.ContainsKey("patternImage"))
DestinationPatternImage = iniFile["patternImage"];
if (iniFile.ContainsKey("patternAudio"))
DestinationPatternAudio = iniFile["patternAudio"];
if (iniFile.ContainsKey("patternVideo"))
DestinationPatternVideo = iniFile["patternVideo"];
if (iniFile.ContainsKey("precondition"))
CopyPrecondition = iniFile["precondition"].ToEnum<CopyPrecondition>();
if (iniFile.ContainsKey("comparator"))
FileComparator = iniFile["comparator"].ToEnum<FileComparator>();
if (iniFile.ContainsKey("copyMode"))
CopyMode = iniFile["copyMode"].ToEnum<CopyMode>();
if (iniFile.ContainsKey("exceptionHandling"))
ExceptionHandling = iniFile["exceptionHandling"].ToEnum<ExceptionHandling>();
if (iniFile.ContainsKey("verifyFiles"))
VerifyFiles = iniFile["verifyFiles"].ToBool();
}

public void SaveConfig()
Expand All @@ -168,6 +186,15 @@ public void SaveConfig()
iniFile["sourcePath"] = sourcePath;
iniFile["destinationPath"] = destinationPath;
iniFile["recursive"] = Recursive ? "1" : "0";
iniFile["locale"] = Localization.Name;
iniFile["patternImage"] = DestinationPatternImage;
iniFile["patternAudio"] = DestinationPatternAudio;
iniFile["patternVideo"] = DestinationPatternVideo;
iniFile["precondition"] = CopyPrecondition.ToString();
iniFile["comparator"] = FileComparator.ToString();
iniFile["copyMode"] = CopyMode.ToString();
iniFile["exceptionHandling"] = ExceptionHandling.ToString();
iniFile["verifyFiles"] = VerifyFiles ? "1" : "0";

string iniFilePath = IniConfigFileName;
iniFile.TrySave(iniFilePath);
Expand Down
11 changes: 10 additions & 1 deletion MediaOrganizer/MediaOrganizer.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
sourcePath: C:\temp
destinationPath: C:\temp\backup
recursive: 1
recursive: 1
locale: sv-SE
patternImage: %y/%m %M/%t/%n.%e
patternAudio: %y/%m %M/Audio/%t/%n.%e
patternVideo: %y/%m %M/Video/%t/%n.%e
precondition: None
comparator: FileSize, Checksum
copyMode: KeepUnique
exceptionHandling: Throw
verifyFiles: 1
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Features:

GUI:
0.2 - separate settings/advanced form for improved usability
0.1 - Remember GUI settings (MediaOrganizer.ini)
- button to run prepare and prinotut information about copying
- Separate progress of Parse() and Organize into 0.0-1.0 for each + message in event
- Printout how many skipped files (grouped by extension/type)

0 comments on commit 89bb6e4

Please sign in to comment.