Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.

Commit 19ad6d7

Browse files
committed
add extra columns (launch arguments, git branch), make custom arguments cell editable with F2, load/save custom launcher arguments, launch with custom arguments, display GIT branch info, gridviews disable TAB stop on cells
1 parent 2660ab9 commit 19ad6d7

File tree

3 files changed

+159
-58
lines changed

3 files changed

+159
-58
lines changed

UnityLauncher/Form1.Designer.cs

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

UnityLauncher/Form1.cs

+93-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public partial class Form1 : Form
1717
public static Dictionary<string, string> unityList = new Dictionary<string, string>();
1818
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
1919
bool isDownloadUnityList = false;
20+
const string launcherArgumentsFile = "LauncherArguments.txt";
2021

2122

2223
public Form1()
@@ -286,9 +287,14 @@ void FilterRecentProject(object sender, EventArgs e)
286287
SetStatus("Filtering recent projects list..");
287288
foreach (DataGridViewRow recentProject in gridRecent.Rows)
288289
{
289-
if (recentProject.Cells["_project"].Value.ToString().ToLower().Contains(tbSearchBar.Text.ToLower()))
290+
if (recentProject.Cells["_project"].Value.ToString().IndexOf(tbSearchBar.Text, StringComparison.OrdinalIgnoreCase) > -1)
291+
{
290292
recentProject.Visible = true;
291-
else recentProject.Visible = false;
293+
}
294+
else
295+
{
296+
recentProject.Visible = false;
297+
}
292298
}
293299
}
294300

@@ -365,7 +371,13 @@ void UpdateRecentProjectsList()
365371
// get project version
366372
string projectVersion = GetProjectVersion(projectPath);
367373

368-
gridRecent.Rows.Add(projectName, projectVersion, projectPath, lastUpdated);
374+
// get custom launch arguments,TODO if enabled
375+
string customArgs = ReadCustomLaunchArguments(projectPath);
376+
377+
// get git branchinfo,TODO if enabled
378+
string gitBranch = ReadGitBranchInfo(projectPath);
379+
380+
gridRecent.Rows.Add(projectName, projectVersion, projectPath, lastUpdated, customArgs, gitBranch);
369381
gridRecent.Rows[gridRecent.Rows.Count - 1].Cells[1].Style.ForeColor = HaveExactVersionInstalled(projectVersion) ? Color.Green : Color.Red;
370382
}
371383
}
@@ -420,6 +432,14 @@ void LaunchProject(string projectPath, string version, bool openProject = true)
420432
if (openProject == true)
421433
{
422434
var pars = " -projectPath " + "\"" + projectPath + "\"";
435+
436+
// check for custom launch parameters and append them
437+
string customArguments = GetSelectedRowData("_launchArguments");
438+
if (string.IsNullOrEmpty(customArguments) == false)
439+
{
440+
pars += " " + customArguments;
441+
}
442+
423443
myProcess.StartInfo.Arguments = pars;
424444
}
425445
myProcess.Start();
@@ -627,6 +647,8 @@ void LaunchSelectedProject(bool openProject = true)
627647
}
628648
}
629649

650+
651+
630652
void LaunchSelectedUnity()
631653
{
632654
var selected = gridUnityList.CurrentCell.RowIndex;
@@ -827,7 +849,9 @@ private void unityGridView_KeyDown(object sender, KeyEventArgs e)
827849
/// <param name="e"></param>
828850
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
829851
{
830-
//Console.WriteLine((int)e.KeyChar);
852+
// if editing cells, dont focus on search
853+
if (gridRecent.IsCurrentCellInEditMode == true) return;
854+
831855
switch ((int)e.KeyChar)
832856
{
833857
case 27: // ESC - clear search
@@ -860,7 +884,9 @@ private void Form1_KeyPress(object sender, KeyPressEventArgs e)
860884
/// <param name="e"></param>
861885
private void gridRecent_KeyDown(object sender, KeyEventArgs e)
862886
{
863-
//Console.WriteLine(e.KeyValue);
887+
// if editing cells, dont search or launch
888+
if (gridRecent.IsCurrentCellInEditMode == true) return;
889+
864890
switch (e.KeyCode)
865891
{
866892
case Keys.Return: // launch selected project
@@ -1197,5 +1223,67 @@ private void UnityVersionsListDownloaded(object sender, DownloadStringCompletedE
11971223
gridUnityUpdates.Rows.Add(row[3], row[6].Trim('"'));
11981224
}
11991225
}
1226+
1227+
// after editing launch arguments cell
1228+
private void gridRecent_CellEndEdit(object sender, DataGridViewCellEventArgs e)
1229+
{
1230+
string path = GetSelectedRowData("_path");
1231+
if (string.IsNullOrEmpty(path)) return;
1232+
1233+
1234+
string arguments = GetSelectedRowData("_launchArguments");
1235+
1236+
// save arguments to projectsettings folder
1237+
string outputFile = Path.Combine(path, "ProjectSettings", launcherArgumentsFile);
1238+
1239+
try
1240+
{
1241+
StreamWriter sw = new StreamWriter(outputFile);
1242+
sw.WriteLine(arguments);
1243+
sw.Close();
1244+
}
1245+
catch (Exception exception)
1246+
{
1247+
SetStatus("File error: " + exception.Message);
1248+
}
1249+
// TODO: keep current row selected
1250+
}
1251+
1252+
// returns currently selected rows path string
1253+
string GetSelectedRowData(string key)
1254+
{
1255+
string path = null;
1256+
var selected = gridRecent.CurrentCell.RowIndex;
1257+
if (selected > -1)
1258+
{
1259+
path = gridRecent.Rows[selected].Cells[key].Value?.ToString();
1260+
}
1261+
return path;
1262+
}
1263+
1264+
string ReadCustomLaunchArguments(string projectPath)
1265+
{
1266+
string results = null;
1267+
string argumentsFile = Path.Combine(projectPath, "ProjectSettings", launcherArgumentsFile);
1268+
if (File.Exists(argumentsFile) == true)
1269+
{
1270+
results = File.ReadAllText(argumentsFile);
1271+
}
1272+
return results;
1273+
}
1274+
1275+
string ReadGitBranchInfo(string projectPath)
1276+
{
1277+
string results = null;
1278+
string branchFile = Path.Combine(projectPath, ".git", "HEAD");
1279+
if (File.Exists(branchFile) == true)
1280+
{
1281+
results = File.ReadAllText(branchFile);
1282+
// get branch only
1283+
int pos = results.LastIndexOf("/") + 1;
1284+
results = results.Substring(pos, results.Length - pos);
1285+
}
1286+
return results;
1287+
}
12001288
}
12011289
}

UnityLauncher/Form1.resx

+2-8
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,10 @@
132132
<metadata name="_dateModified.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
133133
<value>True</value>
134134
</metadata>
135-
<metadata name="_project.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
136-
<value>True</value>
137-
</metadata>
138-
<metadata name="_version.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
135+
<metadata name="_launchArguments.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
139136
<value>True</value>
140137
</metadata>
141-
<metadata name="_path.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
142-
<value>True</value>
143-
</metadata>
144-
<metadata name="_dateModified.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
138+
<metadata name="_gitBranch.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
145139
<value>True</value>
146140
</metadata>
147141
<metadata name="_unityVersion.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

0 commit comments

Comments
 (0)