Skip to content

Commit 50db576

Browse files
committed
remove local build helper scripts for now, update Theme editor to handle read only install location, modify safepath to handle any folder name
1 parent 05c0f31 commit 50db576

File tree

6 files changed

+99
-139
lines changed

6 files changed

+99
-139
lines changed

InstallerBumpVersion.bat

-59
This file was deleted.

InstallerGUIDGen.vbs

-3
This file was deleted.

UnityLauncherPro/MainWindow.xaml.cs

+32-56
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public partial class MainWindow : Window
4343
public static readonly string projectNameFile = "ProjectName.txt";
4444
public static string preferredVersion = null;
4545
public static int projectNameSetting = 0; // 0 = folder or ProjectName.txt if exists, 1=ProductName
46-
public static readonly string initScriptFileFullPath = GetInitScriptPath();
46+
public static readonly string initScriptFileFullPath = Tools.GetSafeFilePath("Scripts", "InitializeProject.cs");
4747

4848
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
4949
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro";
@@ -2724,51 +2724,52 @@ private void MenuItemBrowsePersistentDataPath_Click(object sender, RoutedEventAr
27242724
}
27252725
}
27262726

2727-
void ApplyTheme(string themeFile)
2727+
private void ApplyTheme(string themeFileName)
27282728
{
2729-
if (chkUseCustomTheme.IsChecked == false) return;
2730-
2731-
//Console.WriteLine("Load theme: " + themefile);
2729+
if (chkUseCustomTheme.IsChecked != true)
2730+
return;
27322731

2733-
themeFile = "Themes/" + themeFile;
2732+
// 1) Compute the full, safe path to the INI
2733+
string themePath = Tools.GetSafeFilePath("Themes", themeFileName);
27342734

2735-
if (File.Exists(themeFile) == true)
2735+
// 2) Try to load it
2736+
if (File.Exists(themePath))
27362737
{
2737-
var colors = File.ReadAllLines(themeFile);
2738-
2739-
// parse lines
2740-
for (int i = 0, length = colors.Length; i < length; i++)
2738+
var lines = File.ReadAllLines(themePath);
2739+
for (int i = 0; i < lines.Length; i++)
27412740
{
2742-
// skip comments
2743-
if (colors[i].IndexOf('#') == 0) continue;
2744-
// split row (name and color)
2745-
var row = colors[i].Split('=');
2746-
// skip bad rows
2747-
if (row.Length != 2) continue;
2748-
2749-
// parse color
2741+
string line = lines[i].Trim();
2742+
// skip empty or comment
2743+
if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
2744+
continue;
2745+
2746+
var parts = line.Split(new[] { '=' }, 2);
2747+
if (parts.Length != 2)
2748+
continue;
2749+
2750+
string key = parts[0].Trim();
2751+
string value = parts[1].Trim();
2752+
27502753
try
27512754
{
2752-
//Console.WriteLine(row[0] +"="+ row[1].Trim());
2753-
var col = new BrushConverter().ConvertFrom(row[1].Trim());
2754-
// apply color
2755-
Application.Current.Resources[row[0]] = (SolidColorBrush)col;
2755+
var brush = (SolidColorBrush)new BrushConverter().ConvertFrom(value);
2756+
Application.Current.Resources[key] = brush;
27562757
}
2757-
catch (Exception e)
2758+
catch (Exception ex)
27582759
{
2759-
Console.WriteLine(e);
2760-
SetStatus("Failed to parse color value: " + row[1]);
2760+
Console.WriteLine(ex);
2761+
SetStatus($"Failed to parse color value: {value}");
27612762
}
2762-
27632763
}
27642764
}
27652765
else
27662766
{
2767-
Console.WriteLine("Theme file not found: " + themeFile);
2768-
SetStatus("Theme file not found: " + themeFile);
2767+
Console.WriteLine($"Theme file not found: {themePath}");
2768+
SetStatus($"Theme file not found: {themePath}");
27692769
}
27702770
}
27712771

2772+
27722773
void ResetTheme()
27732774
{
27742775
foreach (DictionaryEntry item in Application.Current.Resources.MergedDictionaries[0])
@@ -2809,8 +2810,8 @@ private void BtnReloadTheme_Click(object sender, RoutedEventArgs e)
28092810
private void TxtCustomThemeFile_LostFocus(object sender, RoutedEventArgs e)
28102811
{
28112812
var s = (TextBox)sender;
2812-
Properties.Settings.Default.themeFile = s.Text;
2813-
Properties.Settings.Default.Save();
2813+
Settings.Default.themeFile = s.Text;
2814+
Settings.Default.Save();
28142815
}
28152816

28162817
private void TxtCustomThemeFile_PreviewKeyDown(object sender, KeyEventArgs e)
@@ -4105,31 +4106,6 @@ private void btnPurgeMissingFolders_Click(object sender, RoutedEventArgs e)
41054106
SetStatus("Purged " + removedCount + " items", MessageType.Info);
41064107
}
41074108

4108-
// to handle folders where user has no write access ()
4109-
private static string GetInitScriptPath()
4110-
{
4111-
string preferredDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts");
4112-
string fallbackDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UnityLauncherPro", "Scripts");
4113-
4114-
try
4115-
{
4116-
Directory.CreateDirectory(preferredDir); // safe even if it exists
4117-
return Path.Combine(preferredDir, "InitializeProject.cs");
4118-
}
4119-
catch (UnauthorizedAccessException)
4120-
{
4121-
// No write permission in Program Files etc.
4122-
}
4123-
catch (Exception ex)
4124-
{
4125-
// Optional: log other unexpected errors
4126-
Console.WriteLine("Init folder fallback: " + ex.Message);
4127-
}
4128-
4129-
Directory.CreateDirectory(fallbackDir); // always safe
4130-
return Path.Combine(fallbackDir, "InitializeProject.cs");
4131-
}
4132-
41334109
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
41344110
//{
41354111
// var proj = GetSelectedProject();

UnityLauncherPro/ThemeEditor.xaml.cs

+32-20
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,47 @@ private void GridThemeColors_SelectionChanged(object sender, SelectionChangedEve
109109

110110
private void BtnSaveTheme_Click(object sender, RoutedEventArgs e)
111111
{
112-
var themeFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Themes");
113-
114-
if (Directory.Exists(themeFolder) == false) Directory.CreateDirectory(themeFolder);
115-
116-
SaveFileDialog saveFileDialog = new SaveFileDialog();
117-
if (string.IsNullOrEmpty(previousSaveFileName))
118-
{
119-
saveFileDialog.FileName = "custom";
120-
}
121-
else
112+
// 1) Determine the default filename (with .ini)
113+
string defaultName = string.IsNullOrEmpty(previousSaveFileName)
114+
? "custom.ini"
115+
: previousSaveFileName + ".ini";
116+
117+
// 2) Ask the helper for a safe full path
118+
string initialFullPath = Tools.GetSafeFilePath("Themes", defaultName);
119+
string initialDir = Path.GetDirectoryName(initialFullPath);
120+
string initialFile = Path.GetFileNameWithoutExtension(initialFullPath);
121+
122+
// 3) Configure the save dialog
123+
var saveFileDialog = new SaveFileDialog
122124
{
123-
saveFileDialog.FileName = previousSaveFileName;
124-
}
125-
saveFileDialog.DefaultExt = ".ini";
126-
saveFileDialog.Filter = "Theme files (.ini)|*.ini";
127-
saveFileDialog.InitialDirectory = themeFolder;
128-
saveFileDialog.RestoreDirectory = true;
129-
125+
FileName = initialFile, // no extension here
126+
DefaultExt = ".ini",
127+
Filter = "Theme files (.ini)|*.ini",
128+
InitialDirectory = initialDir,
129+
RestoreDirectory = true
130+
};
131+
132+
// 4) Show and, if confirmed, write out the INI
130133
if (saveFileDialog.ShowDialog() == true)
131134
{
132-
List<string> iniRows = new List<string>();
133-
iniRows.Add("# Created with UnityLauncherPro built-in theme editor " + DateTime.Now.ToString("dd/MM/yyyy"));
135+
// Build INI lines
136+
var iniRows = new List<string>
137+
{
138+
"# Created with UnityLauncherPro built-in theme editor "
139+
+ DateTime.Now.ToString("dd/MM/yyyy")
140+
};
141+
// original-style loop
134142
for (int i = 0; i < themeColors.Count; i++)
135143
{
136144
iniRows.Add(themeColors[i].Key + "=" + themeColors[i].Brush.ToString());
137145
}
138146

139-
var themePath = saveFileDialog.FileName;
147+
// Get the chosen path & ensure its folder exists
148+
string themePath = saveFileDialog.FileName;
140149
previousSaveFileName = Path.GetFileNameWithoutExtension(themePath);
150+
Directory.CreateDirectory(Path.GetDirectoryName(themePath));
151+
152+
// Write out
141153
File.WriteAllLines(themePath, iniRows);
142154
Console.WriteLine("Saved theme: " + themePath);
143155
}

UnityLauncherPro/Tools.cs

+35
Original file line numberDiff line numberDiff line change
@@ -2779,7 +2779,42 @@ internal static bool RunExclusionElevated(IEnumerable<string> paths, bool silent
27792779
return true;
27802780
}
27812781

2782+
/// <summary>
2783+
/// Returns a full file path under either the application's install folder
2784+
/// or, if that isn't writable, under LocalAppData\UnityLauncherPro\<subfolder>.
2785+
/// </summary>
2786+
/// <param name="subfolder">e.g. "Themes", "Scripts"</param>
2787+
/// <param name="fileName">e.g. "custom.ini", "InitializeProject.cs"</param>
2788+
public static string GetSafeFilePath(string subfolder, string fileName)
2789+
{
2790+
// 1) Preferred: under the app folder
2791+
string preferredDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, subfolder);
2792+
// 2) Fallback: in LocalAppData
2793+
string fallbackDir = Path.Combine(
2794+
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
2795+
"UnityLauncherPro",
2796+
subfolder);
2797+
2798+
try
2799+
{
2800+
// Safe even if it already exists
2801+
Directory.CreateDirectory(preferredDir);
2802+
return Path.Combine(preferredDir, fileName);
2803+
}
2804+
catch (UnauthorizedAccessException)
2805+
{
2806+
// no write access under Program Files
2807+
}
2808+
catch (Exception ex)
2809+
{
2810+
// optional: log unexpected errors
2811+
Console.WriteLine($"Warning: couldn’t create {preferredDir}: {ex.Message}");
2812+
}
27822813

2814+
// Ensure fallback always exists
2815+
Directory.CreateDirectory(fallbackDir);
2816+
return Path.Combine(fallbackDir, fileName);
2817+
}
27832818

27842819

27852820

installer-version.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)