Skip to content

Portable Tool for an Ideal Windows Setup

fix Unicode path support for INI files

Greedeks2061014ab1a7
diff --git a/.Source/GTweak/Utilities/Controls/SettingsEngine.cs b/.Source/GTweak/Utilities/Controls/SettingsEngine.cs
index 28f2f10b..501ff611 100644
--- a/.Source/GTweak/Utilities/Controls/SettingsEngine.cs
+++ b/.Source/GTweak/Utilities/Controls/SettingsEngine.cs
@@ -6,6 +6,7 @@ using Microsoft.Win32;
using Ookii.Dialogs.Wpf;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -98,8 +99,11 @@ namespace GTweak.Utilities.Controls
try
{
- PathLocator.Files.Config = Path.Combine(Path.GetDirectoryName(vistaSaveFileDialog.FileName), Path.GetFileNameWithoutExtension(vistaSaveFileDialog.FileName) + ".ini");
+ PathLocator.Files.Config = vistaSaveFileDialog.FileName;
+ if (Path.GetExtension(PathLocator.Files.Config)?.ToLower() != ".ini")
+ PathLocator.Files.Config = Path.ChangeExtension(PathLocator.Files.Config, ".ini");
+
if (File.Exists(PathLocator.Files.Config))
File.Delete(PathLocator.Files.Config);
diff --git a/.Source/GTweak/Utilities/Managers/INIManager.cs b/.Source/GTweak/Utilities/Managers/INIManager.cs
index cac6bffe..503a505a 100644
--- a/.Source/GTweak/Utilities/Managers/INIManager.cs
+++ b/.Source/GTweak/Utilities/Managers/INIManager.cs
@@ -8,13 +8,16 @@ namespace GTweak.Utilities.Managers
{
internal sealed class INIManager
{
- [DllImport("kernel32.dll")]
+ [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern long WritePrivateProfileString(string section, string key, string value, string filePath);
- [DllImport("kernel32.dll")]
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int GetPrivateProfileString(string section, string key, string _default, StringBuilder retVal, int size, string filePath);
- [DllImport("kernel32.dll")]
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int GetPrivateProfileSection(string section, StringBuilder retVal, int size, string filePath);
+
private readonly string _pathToConfig;
internal static Dictionary<string, string>
@@ -30,7 +33,7 @@ namespace GTweak.Utilities.Managers
internal const string SectionSvc = "Services Tweaks";
internal const string SectionSys = "System Tweaks";
- internal INIManager(string iniPath) => _pathToConfig = new FileInfo(iniPath).FullName;
+ internal INIManager(string iniPath) => _pathToConfig = $@"\\?\{new FileInfo(iniPath).FullName}";
internal string Read(string section, string key)
{
@@ -57,6 +60,7 @@ namespace GTweak.Utilities.Managers
selectedDictionary.Add(tweak, value.ToString());
}
+
internal bool IsThereSection(string section)
{
StringBuilder retValue = new StringBuilder(255);