Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions IconMapper/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
</startup>
<appSettings>
<add key="IconFolderPath" value="C:\Path\To\Your\Icons"/>
<add key="LastTheme" value ="0"/>
</appSettings>
</configuration>
45 changes: 45 additions & 0 deletions IconMapper/ContextMenuOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IconMapper
{
class ContextMenuOptions
{
public static void contextMenuOptions()
{
// Define the folder containing the icon files
string iconDirectory = @"C:\Path\To\Your\IconFolder";
string contextMenuPath = @"HKEY_CLASSES_ROOT\Directory\shell\ChangeIcon\submenus";
Comment on lines +13 to +17
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Hardcoded paths break consistency with the rest of the application.

The iconDirectory on line 16 is hardcoded to a placeholder path, while the rest of the application (see MainForm.cs lines 175-184, 390-403, 410-434) reads the icon folder from ConfigurationManager.AppSettings["IconFolderPath"]. This creates a critical divergence where registry entries would point to the wrong location.

Additionally, the method name contextMenuOptions() should follow C# PascalCase convention: ContextMenuOptions() or a more descriptive name like RegisterContextMenuEntries().

Proposed fix
-        public static void contextMenuOptions()
+        public static void RegisterContextMenuEntries()
         {
-        // Define the folder containing the icon files
-            string iconDirectory = @"C:\Path\To\Your\IconFolder";
+            // Get the path from App.config like the rest of the application
+            string iconDirectory = System.Configuration.ConfigurationManager.AppSettings["IconFolderPath"];
             string contextMenuPath = @"HKEY_CLASSES_ROOT\Directory\shell\ChangeIcon\submenus";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static void contextMenuOptions()
{
// Define the folder containing the icon files
string iconDirectory = @"C:\Path\To\Your\IconFolder";
string contextMenuPath = @"HKEY_CLASSES_ROOT\Directory\shell\ChangeIcon\submenus";
public static void RegisterContextMenuEntries()
{
// Get the path from App.config like the rest of the application
string iconDirectory = System.Configuration.ConfigurationManager.AppSettings["IconFolderPath"];
string contextMenuPath = @"HKEY_CLASSES_ROOT\Directory\shell\ChangeIcon\submenus";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/ContextMenuOptions.cs` around lines 13 - 17, Replace the hardcoded
iconDirectory in the contextMenuOptions method with the application setting
ConfigurationManager.AppSettings["IconFolderPath"] and rename the method to
follow PascalCase (e.g., ContextMenuOptions or RegisterContextMenuEntries);
update any internal references to the old method name and ensure the registry
path variable contextMenuPath remains unchanged while using the configured
iconDirectory value for all registry entries.


if (Directory.Exists(iconDirectory))
{
// Scan the directory for .ico files
string[] icoFiles = Directory.GetFiles(iconDirectory, "*.ico");

// Create registry key for sub-menu
foreach (var iconFile in icoFiles)
{
string iconName = Path.GetFileNameWithoutExtension(iconFile);

// Add a new key for each icon file in the submenus
string iconRegistryPath = contextMenuPath+"\\"+iconName;

// Create a registry entry for each .ico file
Registry.SetValue(iconRegistryPath, "", iconName);
Registry.SetValue(iconRegistryPath+"\\command", "", "C:\\Path\\To\\YourApp\\ChangeIconApp.exe\" \"%1\" \"{iconFile}\"");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Malformed command string with missing quote and non-interpolated variable.

The command string has critical issues:

  1. Missing opening double-quote before the path (starts with C:\ but ends with a closing quote)
  2. {iconFile} is literal text, not an interpolated variable - the actual icon path won't be substituted

This will write broken registry entries that won't execute correctly.

Proposed fix
-                    Registry.SetValue(iconRegistryPath+"\\command", "", "C:\\Path\\To\\YourApp\\ChangeIconApp.exe\" \"%1\" \"{iconFile}\"");
+                    Registry.SetValue(iconRegistryPath + "\\command", "", $"\"C:\\Path\\To\\YourApp\\ChangeIconApp.exe\" \"%1\" \"{iconFile}\"");

Note: The executable path C:\Path\To\YourApp\ChangeIconApp.exe is also hardcoded and should likely be replaced with the actual application path, e.g., using Application.ExecutablePath.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/ContextMenuOptions.cs` at line 34, Fix the malformed registry
command string passed to Registry.SetValue: ensure the executable path is quoted
correctly, interpolate the actual iconFile variable (not the literal
"{iconFile}"), and avoid hardcoding the exe path by using a runtime value like
Application.ExecutablePath (or another appropriate app path variable). Update
the call to Registry.SetValue that uses iconRegistryPath and iconFile so the
command becomes a properly escaped, quoted string with the executable path and
the iconFile argument inserted (e.g., "\"<exePath>\" \"%1\" \"<iconFile>\"") so
the registry entry executes correctly.


Console.WriteLine("Added {iconFile} to context menu.");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Console.WriteLine statements use literal {variable} instead of string interpolation.

The debug output won't show the actual values - {iconFile} and {iconDirectory} will appear literally.

Proposed fix
-                    Console.WriteLine("Added {iconFile} to context menu.");
+                    Console.WriteLine($"Added {iconFile} to context menu.");
-                Console.WriteLine("The directory '{iconDirectory}' does not exist.");
+                Console.WriteLine($"The directory '{iconDirectory}' does not exist.");

Also applies to: 41-41

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/ContextMenuOptions.cs` at line 36, The Console.WriteLine calls in
ContextMenuOptions.cs are printing the literal "{iconFile}" and
"{iconDirectory}" instead of the variable values; update those Console.WriteLine
invocations to use string interpolation (e.g., $"Added {iconFile} to context
menu." and $"Icon directory: {iconDirectory}") or String.Format so the actual
variables are output; locate the Console.WriteLine usages in the
ContextMenuOptions class and replace the literal-brace strings with
interpolated/ formatted strings.

}
}
else
{
Console.WriteLine("The directory '{iconDirectory}' does not exist.");
}
}
}
}
Comment on lines +1 to +45
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if ContextMenuOptions is referenced anywhere in the codebase
echo "=== Searching for usages of ContextMenuOptions ==="
rg -n "ContextMenuOptions" --type=cs

echo ""
echo "=== Searching for contextMenuOptions method calls ==="
rg -n "contextMenuOptions\s*\(" --type=cs

Repository: blazingvx/IconMapper

Length of output: 318


Remove dead code and fix string interpolation bug.

The ContextMenuOptions class is never called anywhere in the codebase and should be removed. Additionally, the Registry.SetValue() call contains a string interpolation error—{iconFile} will not be substituted because the string lacks the $ prefix. Use an interpolated string like $"C:\\Path\\To\\YourApp\\ChangeIconApp.exe\" \"%1\" \"{iconFile}\"" or string.Format() to inject the actual file path. Finally, note that writing to HKEY_CLASSES_ROOT requires administrative privileges and will fail for non-admin users.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/ContextMenuOptions.cs` around lines 1 - 45, The ContextMenuOptions
class is dead code and should be removed (delete the ContextMenuOptions
class/file) — if you decide to keep it, fix the string interpolation bugs in
contextMenuOptions: use an interpolated string or string.Format for the
Registry.SetValue command and Console.WriteLine (e.g.
Registry.SetValue(iconRegistryPath + "\\command", "",
$"C:\\Path\\To\\YourApp\\ChangeIconApp.exe\" \"%1\" \"{iconFile}\""); and
Console.WriteLine($"Added {iconFile} to context menu.");), ensure iconDirectory
string usage in the error message is interpolated, and remember that writing to
HKEY_CLASSES_ROOT via Registry.SetValue requires administrative privileges and
will fail for non-admin users.

18 changes: 15 additions & 3 deletions IconMapper/Form/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 137 additions & 7 deletions IconMapper/Form/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,86 @@ namespace IconMapper
public partial class MainForm : Form
{
private string selectedIconPath;
private enum Theme { Light, Dark };
Theme themeselected = Theme.Light;

/// <summary>
/// Main Form
/// </summary>
public MainForm()
{
InitializeComponent();
themeselected = (Theme)Convert.ToInt32(ConfigurationManager.AppSettings["LastTheme"]);
setTheme(themeselected);
Comment on lines +23 to +24
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

setTheme method does not exist - this will not compile.

Line 24 calls setTheme(themeselected), but the actual method is named SetApplicationTheme. This is also repeated on line 478.

Additionally, line 23 has no error handling - if LastTheme contains an invalid value, Convert.ToInt32 will throw a FormatException.

Proposed fix
         public MainForm()
         {
             InitializeComponent();
-            themeselected = (Theme)Convert.ToInt32(ConfigurationManager.AppSettings["LastTheme"]);
-            setTheme(themeselected);
+            int themeValue;
+            if (int.TryParse(ConfigurationManager.AppSettings["LastTheme"], out themeValue) 
+                && Enum.IsDefined(typeof(Theme), themeValue))
+            {
+                themeselected = (Theme)themeValue;
+            }
+            SetApplicationTheme(themeselected);
             LoadDrives();
             LoadIcons();
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/Form/MainForm.cs` around lines 23 - 24, Replace the invalid call
to setTheme(themeselected) with the existing SetApplicationTheme method and add
robust parsing/validation for ConfigurationManager.AppSettings["LastTheme"] by
using int.TryParse (or Enum.TryParse) and verifying the parsed value maps to the
Theme enum (e.g., Enum.IsDefined or Enum.TryParse) before casting; if
parsing/validation fails, fall back to a safe default Theme and log or ignore
the bad config to avoid a FormatException—apply the same replacement/fix for the
other occurrence where setTheme is used.

LoadDrives();
LoadIcons();
}

/// <summary>
/// Dark Theme
/// </summary>
private void DarkTheme()
{
// Background and Foreground
this.BackColor = Color.FromArgb(30, 30, 30); // Dark theme
this.ForeColor = Color.White;

// TreeView Styling
folderTreeView.BackColor = Color.FromArgb(45, 45, 48);
folderTreeView.ForeColor = Color.White;
folderTreeView.BorderStyle = BorderStyle.FixedSingle;

// ListBox Styling
iconListBox.BackColor = Color.FromArgb(40, 40, 42);
iconListBox.ForeColor = Color.LightGreen;
iconListBox.BorderStyle = BorderStyle.FixedSingle;

// PictureBox Styling (border if needed)
iconPreviewPictureBox.BackColor = Color.FromArgb(50, 50, 50);
iconPreviewPictureBox.BorderStyle = BorderStyle.FixedSingle;

// Apply Button Styling (if you use a button called applyIconButton)
applyIconButton.BackColor = Color.FromArgb(70, 130, 180); // SteelBlue
applyIconButton.ForeColor = Color.White;
applyIconButton.FlatStyle = FlatStyle.Flat;
applyIconButton.FlatAppearance.BorderColor = Color.White;
applyIconButton.FlatAppearance.BorderSize = 1;

DirectoryFinder.ForeColor = Color.White;
IconBox.ForeColor = Color.White;

themeselected = Theme.Dark;
}

/// <summary>
/// Light Theme (Default)
/// </summary>
private void LightTheme()
{
// Standard Theme
//this.DoubleBuffered = true;
DirectoryFinder.ForeColor = Color.Black;
IconBox.ForeColor = Color.Black;

this.ForeColor = SystemColors.ControlText;
this.BackColor = SystemColors.Control;

folderTreeView.ForeColor = SystemColors.ControlText;
folderTreeView.BackColor = SystemColors.Control;

applyIconButton.ForeColor = SystemColors.ControlText;
applyIconButton.BackColor = SystemColors.Control;

iconListBox.ForeColor = SystemColors.ControlText;
iconListBox.BackColor = SystemColors.Control;

iconPreviewPictureBox.BackColor = SystemColors.Control;
iconPreviewPictureBox.BorderStyle = BorderStyle.None;

themeselected = Theme.Light;
}


/// <summary>
/// Loads the available drives and adds them to the TreeView.
/// </summary>
Expand Down Expand Up @@ -248,6 +320,13 @@ private void RefreshFolderView()
SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);
}

/// <summary>
/// Folder Refresh
/// </summary>
/// <param name="wEventId"></param>
/// <param name="uFlags"></param>
/// <param name="dwItem1"></param>
/// <param name="dwItem2"></param>
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
private static extern void SHChangeNotify(int wEventId, int uFlags, IntPtr dwItem1, IntPtr dwItem2);

Expand Down Expand Up @@ -309,17 +388,16 @@ protected override void OnResize(EventArgs e)
/// <param name="e"></param>
private void SettingsMenuItem_Click(object sender, EventArgs e)
{
string selectedPath = string.Empty;
using (FolderBrowserDialog folderDialog = new FolderBrowserDialog())
{
if (folderDialog.ShowDialog() == DialogResult.OK)
{
string selectedPath = folderDialog.SelectedPath;
// Update app.config with the new path
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["IconFolderPath"].Value = selectedPath;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
MessageBox.Show("Icon folder path updated successfully.");
selectedPath = folderDialog.SelectedPath;

if (UpdateConfig("IconFolderPath", selectedPath))
MessageBox.Show("Icon folder path updated successfully.");

}
}
}
Expand Down Expand Up @@ -388,5 +466,57 @@ private void AboutMenuItem_Click(object sender, EventArgs e)
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}

/// <summary>
/// Change Theme from Menu
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void changeThemeToolStripMenuItem_Click(object sender, EventArgs e)
{
themeselected = themeselected == Theme.Light ? Theme.Dark : Theme.Light;
setTheme(themeselected);

UpdateConfig("LastTheme", Convert.ToString(Convert.ToInt32(themeselected)));

}
Comment on lines +475 to +482
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Same issue: setTheme should be SetApplicationTheme.

Additionally, consider setting themeselected here rather than inside the theme methods to avoid redundant assignments.

Proposed fix
         private void changeThemeToolStripMenuItem_Click(object sender, EventArgs e)
         {
             themeselected = themeselected == Theme.Light ? Theme.Dark : Theme.Light;
-            setTheme(themeselected);
+            SetApplicationTheme(themeselected);
 
             UpdateConfig("LastTheme", Convert.ToString(Convert.ToInt32(themeselected)));
-
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private void changeThemeToolStripMenuItem_Click(object sender, EventArgs e)
{
themeselected = themeselected == Theme.Light ? Theme.Dark : Theme.Light;
setTheme(themeselected);
UpdateConfig("LastTheme", Convert.ToString(Convert.ToInt32(themeselected)));
}
private void changeThemeToolStripMenuItem_Click(object sender, EventArgs e)
{
themeselected = themeselected == Theme.Light ? Theme.Dark : Theme.Light;
SetApplicationTheme(themeselected);
UpdateConfig("LastTheme", Convert.ToString(Convert.ToInt32(themeselected)));
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/Form/MainForm.cs` around lines 475 - 482, The click handler should
call SetApplicationTheme instead of setTheme and assign themeselected in this
handler to avoid redundant assignments inside theme methods; update
changeThemeToolStripMenuItem_Click to flip themeselected (themeselected =
themeselected == Theme.Light ? Theme.Dark : Theme.Light), then call
SetApplicationTheme(themeselected), and finally call UpdateConfig("LastTheme",
Convert.ToString(Convert.ToInt32(themeselected))); also remove any duplicate
themeselected assignments from the theme methods (e.g., methods named
SetLightTheme/SetDarkTheme or SetApplicationTheme overloads) so the theme
selection state is only set here.


/// <summary>
/// Set Theme for the Application
/// </summary>
/// <param name="theme"></param>
private void SetApplicationTheme(Theme theme)
{
if (themeselected == Theme.Light)
LightTheme();
else
DarkTheme();
}
Comment on lines +488 to +494
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

SetApplicationTheme ignores its theme parameter and uses the field instead.

The method accepts a theme parameter but checks themeselected field, making the parameter useless. This also introduces subtle bugs since themeselected is set inside DarkTheme()/LightTheme() methods rather than before calling them.

Proposed fix
         private void SetApplicationTheme(Theme theme)
         {
-            if (themeselected == Theme.Light)
+            if (theme == Theme.Light)
                 LightTheme();
             else
                 DarkTheme();
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private void SetApplicationTheme(Theme theme)
{
if (themeselected == Theme.Light)
LightTheme();
else
DarkTheme();
}
private void SetApplicationTheme(Theme theme)
{
if (theme == Theme.Light)
LightTheme();
else
DarkTheme();
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/Form/MainForm.cs` around lines 488 - 494, SetApplicationTheme
currently ignores its theme parameter and reads the themeselected field, causing
the parameter to be unused and ordering bugs; change SetApplicationTheme to use
the incoming Theme parameter (e.g., assign themeselected = theme or switch on
theme) and then call LightTheme() or DarkTheme() based on that parameter so the
field is set before invoking those methods (update logic in SetApplicationTheme
to check the parameter rather than themeselected and ensure themeselected is
updated prior to calling LightTheme/DarkTheme).


/// <summary>
/// Update Cofig File
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Typo in XML documentation: "Cofig" should be "Config".

         /// <summary>
-        /// Update Cofig File
+        /// Update Config File
         /// </summary>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Update Cofig File
/// <summary>
/// Update Config File
/// </summary>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/Form/MainForm.cs` at line 497, Fix the typo in the XML
documentation comment that reads "Update Cofig File" by updating it to "Update
Config File" in MainForm's XML summary comment; locate the comment above the
related method in the MainForm class (the XML doc immediately preceding the
UpdateConfig/Update... method) and correct the spelling so the summary reads
"Update Config File".

/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="section"></param>
/// <returns></returns>
private bool UpdateConfig(string key, string value, string section = "appSettings")
{
bool retValue = false;
try
{
// Update app.config with the new path
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(section);
}
catch (Exception ex)
{

}

return retValue;
}
Comment on lines +503 to +520
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

UpdateConfig always returns false and silently swallows exceptions.

The method:

  1. Never sets retValue = true on success, so callers (like line 398-399) receive incorrect feedback
  2. Catches exceptions but does nothing with them - failures are completely hidden
  3. Line 510: If the key doesn't exist in settings, Settings[key] returns null and accessing .Value throws NullReferenceException
Proposed fix
         private bool UpdateConfig(string key, string value, string section = "appSettings")
         {
-            bool retValue = false;
             try
             {
-                // Update app.config with the new path
                 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
-                config.AppSettings.Settings[key].Value = value;
+                var setting = config.AppSettings.Settings[key];
+                if (setting == null)
+                {
+                    config.AppSettings.Settings.Add(key, value);
+                }
+                else
+                {
+                    setting.Value = value;
+                }
                 config.Save(ConfigurationSaveMode.Modified);
                 ConfigurationManager.RefreshSection(section);
+                return true;
             }
             catch (Exception ex)
             {
-
+                MessageBox.Show($"Error updating configuration: {ex.Message}", "Configuration Error", 
+                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                return false;
             }
-
-            return retValue;
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private bool UpdateConfig(string key, string value, string section = "appSettings")
{
bool retValue = false;
try
{
// Update app.config with the new path
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(section);
}
catch (Exception ex)
{
}
return retValue;
}
private bool UpdateConfig(string key, string value, string section = "appSettings")
{
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var setting = config.AppSettings.Settings[key];
if (setting == null)
{
config.AppSettings.Settings.Add(key, value);
}
else
{
setting.Value = value;
}
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(section);
return true;
}
catch (Exception ex)
{
MessageBox.Show($"Error updating configuration: {ex.Message}", "Configuration Error",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@IconMapper/Form/MainForm.cs` around lines 503 - 520, The UpdateConfig method
currently always returns false, swallows exceptions, and dereferences a
possibly-null Settings[key]; fix it by checking Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) then var
setting = config.AppSettings.Settings[key]; if setting is null call
config.AppSettings.Settings.Add(key, value) else set setting.Value = value; call
config.Save(ConfigurationSaveMode.Modified) and
ConfigurationManager.RefreshSection(section), then set retValue = true before
returning; in the catch block do not silently ignore the Exception—log or
surface it (e.g. Debug.WriteLine(ex) or show via MessageBox/your logger) and
keep returning false on failure so callers of UpdateConfig get correct feedback.

}
}
Binary file added IconMapper/Icon/dark_mode_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IconMapper/Icon/light_mode_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IconMapper/Icon/themes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions IconMapper/IconMapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContextMenuOptions.cs" />
<Compile Include="Helper\ConfigHelper.cs" />
<Compile Include="Form\MainForm.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -100,6 +101,7 @@
<ItemGroup>
<Content Include="Icon\IconMapper.ico" />
<Content Include="Icon\IconMapper_48.ico" />
<None Include="Icon\themes.png" />
<None Include="Icon\upload_24dp.png" />
<None Include="Icon\settings_24dp.png" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions IconMapper/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions IconMapper/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="upload_24dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icon\upload_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="settings_24dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icon\settings_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="upload_24dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icon\upload_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="themes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icon\themes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>