Skip to content

Commit a259a9e

Browse files
committed
Add custom ProjectName.txt support, Add rename project title (saves into ProjectSettings/ProjectName.txt file), Add setting for taking projectname from Folder or ProjectName.txt override, or from Player settings ProductName field, REMOVED: Project folder rename (it was too dangerous, rather rename folder from Explorer if needed), fixed nullref if pressed F2 (rename) when recent grid was not selected, #BUILD
1 parent b302872 commit a259a9e

File tree

7 files changed

+213
-68
lines changed

7 files changed

+213
-68
lines changed

Diff for: UnityLauncherPro/App.config

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
<setting name="adbLogCatArgs" serializeAs="String">
9797
<value>-s Unity ActivityManager PackageManager dalvikvm DEBUG -v color</value>
9898
</setting>
99+
<setting name="projectName" serializeAs="String">
100+
<value>0</value>
101+
</setting>
99102
</UnityLauncherPro.Properties.Settings>
100103
</userSettings>
101104
</configuration>

Diff for: UnityLauncherPro/GetProjects.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static List<Project> Scan(bool getGitBranch = false, bool getArguments =
8888
string customArgs = "";
8989
if (getArguments == true)
9090
{
91-
customArgs = folderExists ? Tools.ReadCustomLaunchArguments(projectPath, MainWindow.launcherArgumentsFile) : null;
91+
customArgs = folderExists ? Tools.ReadCustomProjectData(projectPath, MainWindow.launcherArgumentsFile) : null;
9292
}
9393

9494
// get git branchinfo, only if column in enabled
@@ -105,7 +105,23 @@ public static List<Project> Scan(bool getGitBranch = false, bool getArguments =
105105
}
106106

107107
var p = new Project();
108-
p.Title = projectName;
108+
109+
switch (MainWindow.projectNameSetting)
110+
{
111+
case 0:
112+
p.Title = Tools.ReadCustomProjectData(projectPath, MainWindow.projectNameFile);
113+
break;
114+
case 1:
115+
p.Title = Tools.ReadProjectName(projectPath);
116+
break;
117+
default:
118+
p.Title = projectName;
119+
break;
120+
}
121+
122+
// if no custom data or no product name found
123+
if (string.IsNullOrEmpty(p.Title)) p.Title = projectName;
124+
109125
p.Version = projectVersion;
110126
p.Path = projectPath;
111127
p.Modified = lastUpdated;

Diff for: UnityLauncherPro/MainWindow.xaml

+8-3
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@
910910
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show git branch column" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" Margin="0,0,0,4" ToolTip="Shows column for project git branch info" HorizontalAlignment="Left"/>
911911
<CheckBox x:Name="chkShowMissingFolderProjects" Content="Show projects that don't exist on disk" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkShowMissingFolderProjects_CheckedChanged" Unchecked="ChkShowMissingFolderProjects_CheckedChanged" Margin="0,0,0,4" ToolTip="List in recent projects, even if the project folder is missing" HorizontalAlignment="Left"/>
912912
<CheckBox x:Name="chkAllowSingleInstanceOnly" Content="Allow single instance only" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkAllowSingleInstanceOnly_CheckedChanged" Unchecked="ChkAllowSingleInstanceOnly_CheckedChanged" Margin="0,0,0,4" ToolTip="Activates already running instance, instead of starting new exe (not working if app is minized to taskbar)" HorizontalAlignment="Left"/>
913-
<CheckBox x:Name="chkEnableProjectRename" Content="Enable Project Rename F2 (Not recommended for beginners)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Can use F2 to rename project folders, Note that project will disappears from list on refresh, unless you open it (since its new path, not in unity recent projects registry)" Checked="ChkEnableProjectRename_Checked" Unchecked="ChkEnableProjectRename_Checked" HorizontalAlignment="Left"/>
913+
<CheckBox x:Name="chkEnableProjectRename" Content="Enable Project title rename (F2)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Renames project title only, DOES NOT rename project folder! New name is saved into ProjectSettings/ProjectName.txt" Checked="ChkEnableProjectRename_Checked" Unchecked="ChkEnableProjectRename_Checked" HorizontalAlignment="Left"/>
914914
<CheckBox x:Name="chkAskNameForQuickProject" Content="Ask name for New Project" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkAskNameForQuickProject_Checked" Unchecked="ChkAskNameForQuickProject_Checked" Margin="0,0,0,4" ToolTip="If disabled, uses automatic quick project naming" HorizontalAlignment="Left"/>
915915
<CheckBox x:Name="chkStreamerMode" Content="Streamer Mode (hide project names and folders)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Hide project names and folders in main view" Checked="ChkStreamerMode_Checked" Unchecked="ChkStreamerMode_Checked" HorizontalAlignment="Left"/>
916916
<CheckBox x:Name="chkShowPlatform" Content="Show current target platform (if exists in .csproj)" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Shows target platform column" Checked="ChkShowPlatform_Checked" Unchecked="ChkShowPlatform_Checked" HorizontalAlignment="Left"/>
@@ -934,15 +934,20 @@
934934

935935
<StackPanel Grid.Row="3" Orientation="Vertical" Margin="5,10,3,3" >
936936
<CheckBox x:Name="chkEnablePlatformSelection" Content="Enable Platform Selection (Experimental!)" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkEnablePlatformSelection_Checked" Unchecked="ChkEnablePlatformSelection_Checked" Margin="0,0,0,4" ToolTip="Select target platform" HorizontalAlignment="Left"/>
937-
<StackPanel Grid.Row="3" Orientation="Horizontal">
937+
<StackPanel Orientation="Horizontal">
938938
<CheckBox x:Name="chkRunAutomatically" Content="Run automatically on startup " Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Run automatically using startup registry key" HorizontalAlignment="Left" Checked="ChkRunAutomatically_Checked" Unchecked="ChkRunAutomatically_Checked"/>
939939
<CheckBox x:Name="chkRunAutomaticallyMinimized" Content="as minimized" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Minimize to tray when started automatically" HorizontalAlignment="Left" Checked="ChkRunAutomaticallyMinimized_Checked" Unchecked="ChkRunAutomaticallyMinimized_Checked"/>
940940
</StackPanel>
941-
<StackPanel Grid.Row="3" Orientation="Horizontal">
941+
<StackPanel Orientation="Horizontal">
942942
<CheckBox x:Name="chkUseCustomLastModified" Content="Date format" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Last modified date format" HorizontalAlignment="Left" Checked="ChkUseCustomLastModified_Checked" Unchecked="ChkUseCustomLastModified_Checked"/>
943943
<TextBox x:Name="txtCustomDateTimeFormat" MinWidth="150" ToolTip="Default is dd/MM/yyyy HH:mm:ss" Padding="0,3,0,0" Margin="5,0,0,0" Text="dd/MM/yyyy HH:mm:ss" LostFocus="TxtCustomDateTimeFormat_LostFocus" TextChanged="TxtCustomDateTimeFormat_TextChanged" />
944944
</StackPanel>
945945
<CheckBox x:Name="chkHumanFriendlyDateTime" Content="Use human friendly last modified" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="Last modified date format" HorizontalAlignment="Left" Checked="ChkHumanFriendlyDateTime_Checked" Unchecked="ChkHumanFriendlyDateTime_Checked"/>
946+
<Label Foreground="{DynamicResource ThemeButtonForeground}">Project name:</Label>
947+
<StackPanel Orientation="Horizontal">
948+
<RadioButton x:Name="radioProjNameFolder" Content="Folder or ProjectName.txt" Foreground="{DynamicResource ThemeButtonForeground}" Margin="4,0,0,0" GroupName="toggleGroupProjectName" IsChecked="True" Checked="RadioProjNameFolder_Checked" ToolTip="Take project name from project folder name OR ProjectName.txt if file exists in ProjectSettings/ folder"/>
949+
<RadioButton x:Name="radioProjNameProductName" Content="Settings ProductName" Foreground="{DynamicResource ThemeButtonForeground}" Margin="5,0,0,0" GroupName="toggleGroupProjectName" Checked="RadioProjNameProductName_Checked" ToolTip="Take project name from player settings ProductName field"/>
950+
</StackPanel>
946951
</StackPanel>
947952
</StackPanel>
948953

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+102-52
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public partial class MainWindow : Window
3030
public static UnityInstallation[] unityInstallationsSource;
3131
public static ObservableDictionary<string, string> unityInstalledVersions = new ObservableDictionary<string, string>(); // versionID and installation folder
3232
public static readonly string launcherArgumentsFile = "LauncherArguments.txt";
33+
public static readonly string projectNameFile = "ProjectName.txt";
3334
public static string preferredVersion = "none";
35+
public static int projectNameSetting = 0; // 0 = folder or ProjectName.txt if exists, 1=ProductName
3436

3537
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
3638
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro";
@@ -396,6 +398,20 @@ void LoadSettings()
396398
adbLogCatArgs = Properties.Settings.Default.adbLogCatArgs;
397399
txtLogCatArgs.Text = adbLogCatArgs;
398400

401+
projectNameSetting = Properties.Settings.Default.projectName;
402+
switch (projectNameSetting)
403+
{
404+
case 0:
405+
radioProjNameFolder.IsChecked = true;
406+
break;
407+
case 1:
408+
radioProjNameProductName.IsChecked = true;
409+
break;
410+
default:
411+
radioProjNameFolder.IsChecked = true;
412+
break;
413+
}
414+
399415
} // LoadSettings()
400416

401417

@@ -458,6 +474,9 @@ private void SaveSettingsOnExit()
458474
}
459475
}
460476
Properties.Settings.Default.gridColumnWidthsBuildReport = gridWidths.ToArray();
477+
478+
Properties.Settings.Default.projectName = projectNameSetting;
479+
461480
Properties.Settings.Default.Save();
462481

463482
}
@@ -621,7 +640,7 @@ Project GetNewProjectData(string folder)
621640
p.Path = folder;
622641
p.Title = Path.GetFileName(folder);
623642
p.Version = Tools.GetProjectVersion(folder);
624-
p.Arguments = Tools.ReadCustomLaunchArguments(folder, MainWindow.launcherArgumentsFile);
643+
p.Arguments = Tools.ReadCustomProjectData(folder, MainWindow.launcherArgumentsFile);
625644
if ((bool)chkShowPlatform.IsChecked == true) p.TargetPlatform = Tools.GetTargetPlatform(folder);
626645
if ((bool)chkShowGitBranchColumn.IsChecked == true) p.GITBranch = Tools.ReadGitBranchInfo(folder);
627646
return p;
@@ -708,8 +727,12 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
708727
break;
709728
case Key.F2: // edit arguments or project name
710729
if (chkEnableProjectRename.IsChecked == false) return; //if rename not enabled
711-
// if in first cell (or no cell)
730+
731+
// if not inside datagrid, cancel
732+
if (Tools.HasFocus(this, gridRecent, true) == false) return;
733+
712734
var cell = gridRecent.CurrentCell;
735+
// if in first cell (or no cell)
713736
if (cell.Column.DisplayIndex == 0)
714737
{
715738
// enable cell edit
@@ -1295,75 +1318,88 @@ private void GridRecent_CellEditEnding(object sender, DataGridCellEditEndingEven
12951318
var proj = GetSelectedProject();
12961319

12971320
// check that folder exists
1298-
string path = proj.Path;
1299-
if (string.IsNullOrEmpty(path))
1321+
string projectPath = proj.Path;
1322+
if (string.IsNullOrEmpty(projectPath))
13001323
{
13011324
return;
13021325
}
13031326

13041327
// check if we edited project name, or launcher arguments
13051328
if (e.Column.DisplayIndex == 0)
13061329
{
1330+
// NOTE cannot rename folder anymore, too dangerous, rename creates custom ProjectName.txt to keep track of projectname
1331+
13071332
// get current arguments, after editing
13081333
TextBox t = e.EditingElement as TextBox;
1309-
string newcellValue = t.Text.ToString();
1334+
string newProjectNameString = t.Text.ToString();
13101335

13111336
// restore read only
13121337
e.Column.IsReadOnly = true;
13131338

1314-
if (string.IsNullOrEmpty(newcellValue))
1315-
{
1316-
Console.WriteLine("Project name is null: " + newcellValue);
1317-
return;
1318-
}
1319-
1320-
// cannot allow / or \ or . as last character (otherwise might have issues going parent folder?)
1321-
if (newcellValue.EndsWith("\\") || newcellValue.EndsWith("/") || newcellValue.EndsWith("."))
1339+
if (string.IsNullOrEmpty(newProjectNameString))
13221340
{
1323-
Console.WriteLine("Project name cannot end with / or \\ or . ");
1341+
Console.WriteLine("Project name is null: " + newProjectNameString);
13241342
return;
13251343
}
13261344

1327-
// get new path
1328-
var newPath = Path.Combine(Directory.GetParent(path).ToString(), newcellValue);
1329-
1330-
// check if has invalid characters for full path
1331-
if (newPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
1332-
{
1333-
Console.WriteLine("Invalid project path: " + newPath);
1334-
return;
1335-
}
1336-
1337-
// check if same as before (need to replace mismatch slashes)
1338-
if (path.Replace('/', '\\') == newPath.Replace('/', '\\'))
1345+
//// cannot allow / or \ or . as last character (otherwise might have issues going parent folder?)
1346+
//if (newProjectNameString.EndsWith("\\") || newProjectNameString.EndsWith("/") || newProjectNameString.EndsWith("."))
1347+
//{
1348+
// Console.WriteLine("Project name cannot end with / or \\ or . ");
1349+
// return;
1350+
//}
1351+
1352+
//// get new path
1353+
//var newPath = Path.Combine(Directory.GetParent(path).ToString(), newProjectNameString);
1354+
1355+
//// check if has invalid characters for full path
1356+
//if (newPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
1357+
//{
1358+
// Console.WriteLine("Invalid project path: " + newPath);
1359+
// return;
1360+
//}
1361+
1362+
//// check if same as before (need to replace mismatch slashes)
1363+
//if (path.Replace('/', '\\') == newPath.Replace('/', '\\'))
1364+
//{
1365+
// Console.WriteLine("Rename cancelled..");
1366+
// return;
1367+
//}
1368+
1369+
//// check if new folder already exists
1370+
//if (Directory.Exists(newPath))
1371+
//{
1372+
// Console.WriteLine("Directory already exists: " + newPath);
1373+
// return;
1374+
//}
1375+
1376+
//// try rename project folder by moving directory to new name
1377+
//Directory.Move(path, newPath);
1378+
1379+
//// check if move was success
1380+
//if (Directory.Exists(newPath))
1381+
//{
1382+
// // force ending edit (otherwise only ends on enter or esc)
1383+
// gridRecent.CommitEdit(DataGridEditingUnit.Row, true);
1384+
1385+
// // TODO save to registry (otherwise not listed in recent projects, unless opened)
1386+
//}
1387+
//else
1388+
//{
1389+
// Console.WriteLine("Failed to rename directory..");
1390+
//}
1391+
1392+
var write = Tools.SaveCustomProjectData(projectPath, projectNameFile, newProjectNameString);
1393+
// write success, otherwise keep old name
1394+
if (write == true)
13391395
{
1340-
Console.WriteLine("Rename cancelled..");
1341-
return;
1342-
}
1343-
1344-
// check if new folder already exists
1345-
if (Directory.Exists(newPath))
1346-
{
1347-
Console.WriteLine("Directory already exists: " + newPath);
1348-
return;
1349-
}
1350-
1351-
// try rename project folder by moving directory to new name
1352-
Directory.Move(path, newPath);
1353-
1354-
// check if move was success
1355-
if (Directory.Exists(newPath))
1356-
{
1357-
// force ending edit (otherwise only ends on enter or esc)
13581396
gridRecent.CommitEdit(DataGridEditingUnit.Row, true);
1359-
1360-
// TODO save to registry (otherwise not listed in recent projects, unless opened)
1361-
}
1362-
else
1363-
{
1364-
Console.WriteLine("Failed to rename directory..");
1397+
proj.Title = newProjectNameString;
1398+
Console.WriteLine("Project title renamed to: " + newProjectNameString);
1399+
gridRecent.Items.Refresh();
13651400
}
13661401

1402+
13671403
}
13681404
else if (e.Column.DisplayIndex == 4) // edit launcher arguments
13691405
{
@@ -1374,14 +1410,14 @@ private void GridRecent_CellEditEnding(object sender, DataGridCellEditEndingEven
13741410
string projSettingsFolder = "ProjectSettings";
13751411

13761412
// check if projectsettings folder exists, if not then add
1377-
string outputFolder = Path.Combine(path, projSettingsFolder);
1413+
string outputFolder = Path.Combine(projectPath, projSettingsFolder);
13781414
if (Directory.Exists(outputFolder) == false)
13791415
{
13801416
Directory.CreateDirectory(outputFolder);
13811417
}
13821418

13831419
// save arguments to projectsettings folder
1384-
string outputFile = Path.Combine(path, projSettingsFolder, launcherArgumentsFile);
1420+
string outputFile = Path.Combine(projectPath, projSettingsFolder, launcherArgumentsFile);
13851421

13861422
try
13871423
{
@@ -2288,5 +2324,19 @@ private void MenuItemDownloadLinuxModule_Click(object sender, RoutedEventArgs e)
22882324
if (unity == null) return;
22892325
Tools.DownloadLinuxModules(unity.Path, unity.Version);
22902326
}
2327+
2328+
private void RadioProjNameFolder_Checked(object sender, RoutedEventArgs e)
2329+
{
2330+
projectNameSetting = 0; // default, folder
2331+
if (this.IsActive == false) return; // dont run code on window init
2332+
RefreshRecentProjects();
2333+
}
2334+
2335+
private void RadioProjNameProductName_Checked(object sender, RoutedEventArgs e)
2336+
{
2337+
projectNameSetting = 1; // player settings, product name
2338+
if (this.IsActive == false) return; // dont run code on window init
2339+
RefreshRecentProjects();
2340+
}
22912341
} // class
22922342
} //namespace

Diff for: UnityLauncherPro/Properties/Settings.Designer.cs

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)