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

Commit fa78e52

Browse files
committed
can create new project to any folder with explorer context menu "open with unitylauncher"
1 parent 853eb26 commit fa78e52

File tree

2 files changed

+79
-57
lines changed

2 files changed

+79
-57
lines changed

Diff for: UnityLauncher/Form1.cs

+69-52
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ void Start()
5959
string[] args = Environment.GetCommandLineArgs();
6060
if (args != null && args.Length > 2)
6161
{
62-
var commandArg = args[1];
63-
if (commandArg == "-projectPath")
62+
var commandLineArgs = args[1];
63+
if (commandLineArgs == "-projectPath")
6464
{
6565
SetStatus("Launching from commandline..");
6666

6767
var projectPathArgument = args[2];
68-
6968
var version = GetProjectVersion(projectPathArgument);
7069

7170
LaunchProject(projectPathArgument, version, true);
71+
7272
SetStatus("Ready");
7373

7474
// quit after launch if enabled in settings
@@ -272,7 +272,6 @@ void UpdateRecentProjectsList()
272272
gridRecent.Rows[gridRecent.Rows.Count - 1].Cells[1].Style.ForeColor = HaveExactVersionInstalled(projectVersion) ? Color.Green : Color.Red;
273273
}
274274
}
275-
276275
SetStatus("Ready");
277276
}
278277

@@ -294,36 +293,44 @@ void LaunchProject(string projectPath, string version, bool openProject = true)
294293
{
295294
if (Directory.Exists(projectPath) == true)
296295
{
297-
if (Directory.Exists(Path.Combine(projectPath, "Assets")))
296+
// no assets path, probably we want to create new project then
297+
var assetsFolder = Path.Combine(projectPath, "Assets");
298+
if (Directory.Exists(assetsFolder) == false)
298299
{
299-
//var version = GetProjectVersion(projectPath);
300-
//Console.WriteLine("Detected project version: " + version);
300+
// TODO could ask if want to create project
301+
Directory.CreateDirectory(assetsFolder);
302+
}
301303

302-
bool haveExactVersion = HaveExactVersionInstalled(version);
303-
if (haveExactVersion == true)
304-
{
305-
//Console.WriteLine("Opening unity version " + version);
306-
SetStatus("Launching project in unity " + version);
304+
bool haveExactVersion = HaveExactVersionInstalled(version);
305+
if (haveExactVersion == true)
306+
{
307+
//Console.WriteLine("Opening unity version " + version);
308+
SetStatus("Launching project in unity " + version);
307309

308-
try
309-
{
310-
Process myProcess = new Process();
311-
var cmd = "\"" + unityList[version] + "\"";
312-
myProcess.StartInfo.FileName = cmd;
313-
if (openProject == true)
314-
{
315-
var pars = " -projectPath " + "\"" + projectPath + "\"";
316-
myProcess.StartInfo.Arguments = pars;
317-
}
318-
myProcess.Start();
319-
}
320-
catch (Exception ex)
310+
try
311+
{
312+
Process myProcess = new Process();
313+
var cmd = "\"" + unityList[version] + "\"";
314+
myProcess.StartInfo.FileName = cmd;
315+
if (openProject == true)
321316
{
322-
Console.WriteLine(ex);
317+
var pars = " -projectPath " + "\"" + projectPath + "\"";
318+
myProcess.StartInfo.Arguments = pars;
323319
}
324-
320+
myProcess.Start();
321+
}
322+
catch (Exception ex)
323+
{
324+
Console.WriteLine(ex);
325+
}
326+
}
327+
else // we dont have this version installed (or no version info available)
328+
{
329+
if (string.IsNullOrEmpty(version) == true)
330+
{
331+
DisplayUpgradeDialog(version, projectPath);
325332
}
326-
else // we dont have this version installed
333+
else // offer to download or open web
327334
{
328335
SetStatus("Missing unity version: " + version);
329336

@@ -351,10 +358,6 @@ void LaunchProject(string projectPath, string version, bool openProject = true)
351358
}
352359
}
353360
}
354-
else
355-
{
356-
SetStatus("No Assets folder founded in: " + projectPath);
357-
}
358361
}
359362
else // given path doesnt exists, strange
360363
{
@@ -877,40 +880,54 @@ private static string FindNearestVersionFromSimilarVersions(string version, IEnu
877880
return null;
878881
}
879882

883+
// displays version selector to upgrade project
880884
void UpgradeProject()
881885
{
882886
var selected = gridRecent.CurrentCell.RowIndex;
883887
if (selected > -1)
884888
{
885889
SetStatus("Upgrading project..");
886890

887-
var path = gridRecent.Rows[selected].Cells["_path"].Value.ToString();
888-
var currentVersion = GetProjectVersion(path);
889-
890-
bool haveExactVersion = HaveExactVersionInstalled(currentVersion);
891-
if (haveExactVersion == true)
892-
{
893-
// you already have same version, are you sure?
894-
}
895-
896-
Form2 upgradeDialog = new Form2();
897-
Form2.currentVersion = currentVersion;
891+
var projectPath = gridRecent.Rows[selected].Cells["_path"].Value.ToString();
892+
var currentVersion = GetProjectVersion(projectPath);
898893

899-
if (upgradeDialog.ShowDialog(this) == DialogResult.OK)
894+
if (string.IsNullOrEmpty(currentVersion) == true)
900895
{
901-
// yes, upgrade
902-
SetStatus("Upgrading project to " + Form2.currentVersion);
903-
var projectPath = gridRecent.Rows[selected].Cells["_path"].Value.ToString();
904-
LaunchProject(projectPath, Form2.currentVersion);
896+
// TODO no version info available, should handle errors?
905897
}
906-
else
898+
else // have version info
907899
{
908-
// cancelled
909-
SetStatus("Cancelled project upgrade");
900+
bool haveExactVersion = HaveExactVersionInstalled(currentVersion);
901+
if (haveExactVersion == true)
902+
{
903+
// you already have exact version, are you sure about upgrade?
904+
}
910905
}
911-
upgradeDialog.Close();
912906

907+
DisplayUpgradeDialog(currentVersion, projectPath, true);
908+
}
909+
}
910+
911+
void DisplayUpgradeDialog(string currentVersion, string projectPath, bool launchProject = true)
912+
{
913+
// display upgrade dialog (version selector)
914+
Form2 upgradeDialog = new Form2();
915+
Form2.currentVersion = currentVersion;
916+
917+
if (upgradeDialog.ShowDialog(this) == DialogResult.OK)
918+
{
919+
// yes, upgrade
920+
SetStatus("Upgrading project to " + Form2.currentVersion);
921+
if (launchProject == true) LaunchProject(projectPath, Form2.currentVersion);
922+
}
923+
else
924+
{
925+
// cancelled
926+
SetStatus("Cancelled project upgrade");
913927
}
928+
929+
upgradeDialog.Close();
914930
}
931+
915932
}
916933
}

Diff for: UnityLauncher/Form2.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public Form2()
2121

2222
private void Form2_Load(object sender, EventArgs e)
2323
{
24-
// fill textbox
25-
txtUpgradeCurrentVersion.Text = currentVersion;
24+
Start();
25+
}
2626

27+
void Start()
28+
{
2729
// update unity installations list
2830
lstUnityVersions.Items.AddRange(Form1.unityList.Keys.ToArray());
2931

@@ -40,15 +42,18 @@ private void Form2_Load(object sender, EventArgs e)
4042
lstUnityVersions.SetSelected(likelyIndex, true);
4143
}
4244
}
43-
else // we dont know current version
45+
else // we dont have current version
4446
{
45-
47+
currentVersion = "None";
4648
}
49+
50+
// fill textbox
51+
txtUpgradeCurrentVersion.Text = currentVersion;
4752
}
4853

4954
private void btnConfirmUpgrade_Click(object sender, EventArgs e)
5055
{
51-
if (lstUnityVersions.SelectedIndex>-1)
56+
if (lstUnityVersions.SelectedIndex > -1)
5257
{
5358
currentVersion = lstUnityVersions.Items[lstUnityVersions.SelectedIndex].ToString();
5459
DialogResult = DialogResult.OK;

0 commit comments

Comments
 (0)