Skip to content

Commit

Permalink
Final changes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
hxseven committed Mar 11, 2012
1 parent 2299468 commit d1ce95a
Show file tree
Hide file tree
Showing 45 changed files with 2,139 additions and 1,023 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*.suo
RED2/bin/
RED2/obj/
RED2/publish/
installer_iss/output/
614 changes: 160 additions & 454 deletions LICENSE

Large diffs are not rendered by default.

42 changes: 16 additions & 26 deletions RED2/Lib/ConfigurationManger.cs
Expand Up @@ -10,20 +10,13 @@ public class ConfigurationManger
private Dictionary<string, Control> controls = new Dictionary<string, Control>();
private Dictionary<string, string> defaultValues = new Dictionary<string, string>();

// Registry keys
private string MenuName = "Folder\\shell\\{0}";
private string Command = "Folder\\shell\\{0}\\command";

public event EventHandler OnSettingsSaved;
public int DeletedFolderCount { get; set; }
public int DeletedFolderCount { get; set; }

public ConfigurationManger(string configPath)
{
// Settings object:
settings = new XMLSettings(configPath);

this.MenuName = String.Format(MenuName, RED2.Properties.Resources.registry_name);
this.Command = String.Format(Command, RED2.Properties.Resources.registry_name);
}

public void AddControl(string name, Control c, string defaultValue)
Expand All @@ -32,18 +25,24 @@ public void AddControl(string name, Control c, string defaultValue)
this.defaultValues.Add(name, defaultValue);
}

public IEnumerable<string> GetSettingsList()
{
foreach (var k in this.controls.Keys)
yield return k;
}

public void LoadOptions()
{
foreach (var key in this.controls.Keys)
{
var c = this.controls[key];

if (key == "registry_explorer_integration") ((CheckBox)c).Checked = SystemFunctions.IsRegKeyIntegratedIntoWindowsExplorer(MenuName);
else if (c is CheckBox) ((CheckBox)c).Checked = this.settings.Read(key, Boolean.Parse(this.defaultValues[key]));
if (c is CheckBox) ((CheckBox)c).Checked = this.settings.Read(key, Boolean.Parse(this.defaultValues[key]));
else if (c is TextBox) ((TextBox)c).Text = this.settings.Read(key, SystemFunctions.FixLineBreaks(this.defaultValues[key]));
else if (c is NumericUpDown) ((NumericUpDown)c).Value = (int)this.settings.Read(key, Int32.Parse(this.defaultValues[key]));
else if (c is ComboBox) ((ComboBox)c).SelectedIndex = (int)this.settings.Read(key, Int32.Parse(this.defaultValues[key]));
else if (c is Label) {
else if (c is Label)
{
this.DeletedFolderCount = (int)this.settings.Read(key, Int32.Parse(this.defaultValues[key]));
((Label)c).Text = String.Format(RED2.Properties.Resources.red_deleted, this.DeletedFolderCount);
}
Expand All @@ -59,7 +58,7 @@ public void LoadOptions()
else if (c is TextBox) ((TextBox)c).TextChanged += new EventHandler(Options_CheckedChanged);
else if (c is NumericUpDown) ((NumericUpDown)c).ValueChanged += new EventHandler(Options_CheckedChanged);
else if (c is ComboBox) ((ComboBox)c).SelectedIndexChanged += new EventHandler(Options_CheckedChanged);
else if (!(c is Label))
else if (!(c is Label))
throw new Exception("Unknown control type: " + c.GetType().ToString());
}
}
Expand All @@ -75,15 +74,11 @@ internal void Save()
{
var c = this.controls[key];

if (key == "registry_explorer_integration")
{
SystemFunctions.AddOrRemoveRegKey(!((CheckBox)c).Checked, MenuName, Command);
}
else if (c is CheckBox) this.settings.Write(key, ((CheckBox)c).Checked);
if (c is CheckBox) this.settings.Write(key, ((CheckBox)c).Checked);
else if (c is TextBox) this.settings.Write(key, ((TextBox)c).Text);
else if (c is NumericUpDown) this.settings.Write(key, (int)((NumericUpDown)c).Value);
else if (c is ComboBox) this.settings.Write(key, (int)((ComboBox)c).SelectedIndex);
else if (c is Label) this.settings.Write(key, this.DeletedFolderCount);
else if (c is Label) this.settings.Write(key, this.DeletedFolderCount);
else
throw new Exception("Unknown control type: " + c.GetType().ToString());
}
Expand All @@ -93,14 +88,9 @@ internal void Save()

}

internal int GetCustomSetting(string key, int defaultValue)
{
return this.settings.Read(key, defaultValue);
}

internal void SaveCustom(string key, int value)
internal string GetValue(string key)
{
this.settings.Write(key, value);
return this.settings.Read(key, "");
}
}
}
2 changes: 2 additions & 0 deletions RED2/Lib/Core.cs
Expand Up @@ -68,6 +68,8 @@ void FFWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)

if (info.Type == DirectorySearchStatusTypes.Empty)
this.Data.EmptyFolderList.Add(info.Directory);
else if (info.Type == DirectorySearchStatusTypes.Error && this.Data.HideScanErrors)
return;

if (this.OnFoundEmptyDirectory != null)
this.OnFoundEmptyDirectory(this, info);
Expand Down
1 change: 1 addition & 0 deletions RED2/Lib/RuntimeData.cs
Expand Up @@ -24,6 +24,7 @@ public class RuntimeData
public bool IgnoreEmptyFiles { get; set; }
public bool IgnoreHiddenFolders { get; set; }
public bool KeepSystemFolders { get; set; }
public bool HideScanErrors { get; set; }
public double PauseTime { get; set; }

public int MaxDepth { get; set; }
Expand Down
29 changes: 17 additions & 12 deletions RED2/Lib/SystemFunctions.cs
Expand Up @@ -23,6 +23,10 @@ public enum DeleteModes
/// </summary>
public class SystemFunctions
{
// Registry keys
private const string registryMenuName = "Folder\\shell\\Remove empty dirs";
private const string registryCommand = "Folder\\shell\\Remove empty dirs\\command";

public static string FixLineBreaks(string str)
{
return str.Replace(@"\r\n", "\r\n").Replace(@"\n", "\n");
Expand Down Expand Up @@ -151,26 +155,26 @@ public static void OpenDirectoryWithExplorer(string path)
/// Check for the registry key
/// </summary>
/// <returns></returns>
public static bool IsRegKeyIntegratedIntoWindowsExplorer(string MenuName)
public static bool IsRegKeyIntegratedIntoWindowsExplorer()
{
return (Registry.ClassesRoot.OpenSubKey(MenuName) != null);
return (Registry.ClassesRoot.OpenSubKey(registryMenuName) != null);
}

internal static void AddOrRemoveRegKey(bool remove, string MenuName, string Command)
internal static void AddOrRemoveRegKey(bool add)
{
RegistryKey regmenu = null;
RegistryKey regcmd = null;

if (!remove)
if (add)
{
try
{
regmenu = Registry.ClassesRoot.CreateSubKey(MenuName);
regmenu = Registry.ClassesRoot.CreateSubKey(registryMenuName);

if (regmenu != null)
regmenu.SetValue("", RED2.Properties.Resources.registry_name);
regmenu.SetValue("", "Remove empty dirs");

regcmd = Registry.ClassesRoot.CreateSubKey(Command);
regcmd = Registry.ClassesRoot.CreateSubKey(registryCommand);

if (regcmd != null)
regcmd.SetValue("", Application.ExecutablePath + " \"%1\"");
Expand All @@ -192,22 +196,23 @@ internal static void AddOrRemoveRegKey(bool remove, string MenuName, string Comm
{
try
{
RegistryKey reg = Registry.ClassesRoot.OpenSubKey(Command);
var reg = Registry.ClassesRoot.OpenSubKey(registryCommand);

if (reg != null)
{
reg.Close();
Registry.ClassesRoot.DeleteSubKey(Command);
Registry.ClassesRoot.DeleteSubKey(registryCommand);
}
reg = Registry.ClassesRoot.OpenSubKey(MenuName);
reg = Registry.ClassesRoot.OpenSubKey(registryMenuName);
if (reg != null)
{
reg.Close();
Registry.ClassesRoot.DeleteSubKey(MenuName);
Registry.ClassesRoot.DeleteSubKey(registryMenuName);
}
}
catch (Exception ex)
{
MessageBox.Show(RED2.Properties.Resources.error + "\n\n" + ex.ToString());
MessageBox.Show(RED2.Properties.Resources.error + "\nCould not change registry settings: " + ex.ToString());
}
}
}
Expand Down

0 comments on commit d1ce95a

Please sign in to comment.