Skip to content

Commit 7ec5eae

Browse files
committed
check for crash recovery scene, add show in explorer context menu, show found version count in settings label, show update version in green if already installed, format installed date, get raw installed platform names to unity list,
1 parent 5dbd8ed commit 7ec5eae

File tree

9 files changed

+98
-61
lines changed

9 files changed

+98
-61
lines changed

UnityLauncherPro/App.config

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
<setting name="showGitBranchColumn" serializeAs="String">
4343
<value>False</value>
4444
</setting>
45-
<setting name="showFullModifiedTime" serializeAs="String">
46-
<value>False</value>
47-
</setting>
4845
</UnityLauncherPro.Properties.Settings>
4946
</userSettings>
5047
</configuration>

UnityLauncherPro/Data/UnityInstallation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class UnityInstallation : IValueConverter
1010
public string Version { set; get; }
1111
public string Path { set; get; }
1212
public DateTime? Installed { set; get; }
13-
//public string Platforms { set; get; }
13+
public string Platforms { set; get; }
1414

1515
// color project unity version cells, depending if have that version installed
1616
// https://stackoverflow.com/a/5551986/5452781

UnityLauncherPro/GetProjects.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public static Project[] Scan(bool getGitBranch = false, bool getArguments = fals
9696

9797
// get last modified date
9898
DateTime? lastUpdated = Tools.GetLastModifiedTime(csprojFile);
99-
//Console.WriteLine(lastUpdated.ToString());
10099

101100
// get project version
102101
string projectVersion = Tools.GetProjectVersion(projectPath);

UnityLauncherPro/GetUnityInstallations.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace UnityLauncherPro
99
/// </summary>
1010
public static class GetUnityInstallations
1111
{
12-
//public static UnityInstallation[] Scan(string[] rootFolders)
12+
// returns unity installations
1313
public static UnityInstallation[] Scan()
1414
{
1515
// convert settings list to string array
@@ -48,6 +48,10 @@ public static UnityInstallation[] Scan()
4848
unity.Path = exePath;
4949
unity.Installed = installDate;
5050

51+
// TEST get platforms, NOTE if this is slow, do it later, or skip for commandline
52+
var platforms = GetPlatforms(dataFolder);
53+
unity.Platforms = string.Join(", ", platforms);
54+
5155
// add to list, if not there yet NOTE should notify that there are 2 same versions..? this might happen with preview builds..
5256
if (results.Contains(unity) == true)
5357
{
@@ -56,7 +60,6 @@ public static UnityInstallation[] Scan()
5660
}
5761

5862
results.Add(unity);
59-
6063
} // got folders
6164
} // all root folders
6265

@@ -66,6 +69,21 @@ public static UnityInstallation[] Scan()
6669
return results.ToArray();
6770
} // scan()
6871

72+
//static Dictionary<string, string> platformNames = new Dictionary<string, string> { windowsstandalonesupport};
73+
static string[] GetPlatforms(string dataFolder)
74+
{
75+
// get all folders inside
76+
var directories = Directory.GetDirectories(Path.Combine(dataFolder, "PlaybackEngines"));
77+
// TODO get all platform names from those folders
78+
// TODO get platform foldername only
79+
for (int i = 0; i < directories.Length; i++)
80+
{
81+
directories[i] = Path.GetFileName(directories[i]);
82+
}
83+
84+
return directories;
85+
}
86+
6987
// string to float 2017.4.1f1 > 2017.411
7088
static float VersionAsFloat(string version)
7189
{

UnityLauncherPro/MainWindow.xaml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@
321321
<DataGrid.ContextMenu>
322322
<ContextMenu>
323323
<MenuItem x:Name="menuItemCopyVersion" Header="Copy Unity Version" Click="MenuItemCopyVersion_Click" />
324-
<Separator />
325-
<MenuItem Header="Menu item asdf" />
324+
<!--<Separator />-->
325+
<MenuItem x:Name="menuItemShowProjectInExplorer" Header="Show in Explorer" Click="MenuItemShowProjectInExplorer_Click" />
326326
</ContextMenu>
327327
</DataGrid.ContextMenu>
328328

@@ -422,13 +422,15 @@
422422
<DataGrid.Columns>
423423
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="123"/>
424424
<DataGridTextColumn Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" Header="Path" IsReadOnly="True"/>
425-
<DataGridTextColumn Binding="{Binding Installed}" ClipboardContentBinding="{x:Null}" Header="Installed" IsReadOnly="True"/>
425+
<DataGridTextColumn Binding="{Binding Installed, StringFormat=\{0:dd/MM/yyyy HH:mm:ss\}}" ClipboardContentBinding="{x:Null}" Header="Installed" IsReadOnly="True"/>
426+
<DataGridTextColumn Binding="{Binding Platforms}" ClipboardContentBinding="{x:Null}" Header="Platforms" IsReadOnly="True"/>
426427
</DataGrid.Columns>
427428

428429
<!-- right click context menu -->
429430
<DataGrid.ContextMenu>
430431
<ContextMenu>
431432
<MenuItem x:Name="menuItemCopyVersionInstalled" Header="Copy Unity Version" Click="MenuItemCopyVersion_Click" />
433+
<MenuItem x:Name="menuItemShowUnityInExplorer" Header="Show in Explorer" Click="MenuItemShowProjectInExplorer_Click" />
432434
</ContextMenu>
433435
</DataGrid.ContextMenu>
434436

@@ -497,7 +499,17 @@
497499

498500
<DataGrid.Columns>
499501
<DataGridTextColumn Binding="{Binding ReleaseDate, StringFormat=\{0:dd/MM/yyyy\}}" ClipboardContentBinding="{x:Null}" Header="ReleaseDate" IsReadOnly="True"/>
500-
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="123"/>
502+
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="123">
503+
<DataGridTextColumn.CellStyle>
504+
<Style TargetType="{x:Type DataGridCell}">
505+
<Style.Triggers>
506+
<DataTrigger Binding="{Binding Version, Converter={StaticResource MyConverter}}" Value="true">
507+
<Setter Property="Foreground" Value="#FF00C500" />
508+
</DataTrigger>
509+
</Style.Triggers>
510+
</Style>
511+
</DataGridTextColumn.CellStyle>
512+
</DataGridTextColumn>
501513
</DataGrid.Columns>
502514

503515
<!-- right click context menu -->
@@ -580,7 +592,7 @@
580592

581593
<!-- top labels -->
582594
<Label Grid.Row="0" Content="Unity Installation Parent Folders" Foreground="{DynamicResource ButtonForeground}" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
583-
<Label Grid.Row="0" Content="Found .. Installations" Foreground="{DynamicResource ButtonForeground}" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
595+
<Label x:Name="lblFoundXInstallations" Grid.Row="0" Content="Found .. Installations" Foreground="{DynamicResource ButtonForeground}" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
584596
<!-- locations list -->
585597
<ListBox x:Name="lstRootFolders" Grid.Row="1" Background="#FF3C3C3C" Margin="4,0,2,0" />
586598
<!-- locations add/remove -->
@@ -600,7 +612,6 @@
600612
<CheckBox x:Name="chkQuitAfterCommandline" Content="Close after launching from Explorer" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkQuitAfterCommandline_CheckedChanged" Checked="ChkQuitAfterCommandline_CheckedChanged" Margin="0,0,0,3"/>
601613
<CheckBox x:Name="chkShowLauncherArgumentsColumn" Content="Show Arguments Column" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkShowLauncherArgumentsColumn_CheckedChanged" Checked="ChkShowLauncherArgumentsColumn_CheckedChanged" Margin="0,0,0,3"/>
602614
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show Git Branch Column" Foreground="{DynamicResource ButtonForeground}" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" Margin="0,0,0,3"/>
603-
<CheckBox x:Name="chkShowFullTime" Content="Show full modified time" Foreground="{DynamicResource ButtonForeground}" ToolTip="Full=dd/mm/yyyy hh:mm:ss, NotFull=x hours ago, x days ago.." Margin="0,0,0,3" Checked="ChkShowFullTime_CheckedChanged" Unchecked="ChkShowFullTime_CheckedChanged"/>
604615
</StackPanel>
605616

606617
<!-- links-->

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,18 @@ void HandleCommandLineLaunch()
101101
// NOTE if keydown, window doesnt become active and focused
102102
if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0)
103103
{
104-
//DisplayUpgradeDialog(version, projectPathArgument, launchProject: true, commandLineArguments: commandLineArguments);
105-
//MessageBox.Show("Do you want to Save?", "3", MessageBoxButton.YesNo, MessageBoxImage.Question);
106-
//this.ShowActivated = false;
107-
//Hide();'
108-
//Show();
109-
//Height = 10;
110-
//Width = 10;
111-
//Topmost = true;
112104
Tools.DisplayUpgradeDialog(proj, null);
113105
}
114106
else
115107
{
116-
//MessageBox.Show("Do you want to Save?", "2", MessageBoxButton.YesNo, MessageBoxImage.Question);
117108
// try launching it
118-
//LaunchProject(projectPathArgument, version, openProject: true, commandLineArguments: commandLineArguments);
119109
Tools.LaunchProject(proj);
120110
}
121111

122112
// quit after launch if enabled in settings
123113
if (Properties.Settings.Default.closeAfterExplorer == true)
124114
{
125-
//MessageBox.Show("Do you want to Save?", "quit", MessageBoxButton.YesNo, MessageBoxImage.Question);
126-
//Environment.Exit(0);
115+
Environment.Exit(0);
127116
}
128117
//SetStatus("Ready");
129118
}
@@ -169,7 +158,6 @@ void LoadSettings()
169158
chkQuitAfterOpen.IsChecked = Properties.Settings.Default.closeAfterProject;
170159
chkShowLauncherArgumentsColumn.IsChecked = Properties.Settings.Default.showArgumentsColumn;
171160
chkShowGitBranchColumn.IsChecked = Properties.Settings.Default.showGitBranchColumn;
172-
chkShowFullTime.IsChecked = Properties.Settings.Default.showFullModifiedTime;
173161

174162
// update optional grid columns, hidden or visible
175163
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
@@ -230,14 +218,15 @@ void UpdateUnityInstallationsList()
230218

231219
// make dictionary of installed unitys, to search faster
232220
unityInstalledVersions.Clear();
233-
for (int i = 0; i < unityInstallationsSource.Length; i++)
221+
for (int i = 0, len = unityInstallationsSource.Length; i < len; i++)
234222
{
235223
var version = unityInstallationsSource[i].Version;
236224
if (unityInstalledVersions.ContainsKey(version) == false)
237225
{
238226
unityInstalledVersions.Add(version, unityInstallationsSource[i].Path);
239227
}
240228
}
229+
lblFoundXInstallations.Content = "Found " + unityInstallationsSource.Length + " installations";
241230
}
242231

243232
Project GetSelectedProject()
@@ -293,6 +282,7 @@ async void CallGetUnityUpdates()
293282
dataGridUpdates.ItemsSource = updatesSource;
294283
}
295284

285+
296286
//
297287
//
298288
// EVENTS
@@ -822,11 +812,21 @@ private void ChkQuitAfterCommandline_CheckedChanged(object sender, RoutedEventAr
822812
Properties.Settings.Default.Save();
823813
}
824814

825-
private void ChkShowFullTime_CheckedChanged(object sender, RoutedEventArgs e)
815+
private void MenuItemShowProjectInExplorer_Click(object sender, RoutedEventArgs e)
826816
{
827-
Properties.Settings.Default.showFullModifiedTime = (bool)chkShowFullTime.IsChecked;
828-
Properties.Settings.Default.Save();
817+
string folder = null;
818+
if (tabControl.SelectedIndex == 0)
819+
{
820+
var proj = GetSelectedProject();
821+
folder = proj.Path;
822+
}
823+
else if (tabControl.SelectedIndex == 1)
824+
{
825+
var unity = GetSelectedUnity();
826+
if (unity == null) return;
827+
folder = Path.GetDirectoryName(unity.Path);
828+
}
829+
Tools.LaunchExplorer(folder);
829830
}
830-
831831
} // class
832832
} //namespace

UnityLauncherPro/Properties/Settings.Designer.cs

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityLauncherPro/Properties/Settings.settings

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,5 @@
3535
<Setting Name="gridColumnWidths" Type="System.Int32[]" Scope="User">
3636
<Value Profile="(Default)" />
3737
</Setting>
38-
<Setting Name="showFullModifiedTime" Type="System.Boolean" Scope="User">
39-
<Value Profile="(Default)">False</Value>
40-
</Setting>
4138
</Settings>
4239
</SettingsFile>

UnityLauncherPro/Tools.cs

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,19 @@ public static void LaunchProject(Project proj)
148148
Directory.CreateDirectory(assetsFolder);
149149
}
150150

151-
/*
152-
// TODO when opening project, check for crashed backup scene first
153-
if (openProject == true)
151+
152+
// when opening project, check for crashed backup scene first
153+
var cancelLaunch = CheckCrashBackupScene(proj.Path);
154+
if (cancelLaunch == true)
154155
{
155-
var cancelLaunch = CheckCrashBackupScene(projectPath);
156-
if (cancelLaunch == true)
157-
{
158-
return;
159-
}
160-
}*/
156+
return;
157+
}
161158

162-
// we dont have this version installed (or no version info available)
163-
//MainWindow.unityInstalledVersions;
164159
var unityExePath = GetUnityExePath(proj.Version);
165160
if (unityExePath == null)
166161
{
167-
Console.WriteLine("Missing unity version " + proj.Version);
168-
// SetStatus("Missing Unity version: " + version);
169-
// TODO
170-
//if (openProject == true) DisplayUpgradeDialog(version, projectPath);
162+
//Console.WriteLine("Missing unity version " + proj.Version);
163+
DisplayUpgradeDialog(proj, null);
171164
return;
172165
}
173166

@@ -214,6 +207,40 @@ public static void LaunchProject(Project proj)
214207
}
215208
}
216209

210+
static bool CheckCrashBackupScene(string projectPath)
211+
{
212+
var cancelRunningUnity = false;
213+
var recoveryFile = Path.Combine(projectPath, "Temp", "__Backupscenes", "0.backup");
214+
if (File.Exists(recoveryFile))
215+
{
216+
var result = MessageBox.Show("Crash recovery scene found, do you want to copy it into Assets/_Recovery/-folder?", "UnityLauncherPro - Scene Recovery", MessageBoxButton.YesNo, MessageBoxImage.Question);
217+
if (result == MessageBoxResult.Yes)
218+
{
219+
var restoreFolder = Path.Combine(projectPath, "Assets", "_Recovery");
220+
if (Directory.Exists(restoreFolder) == false)
221+
{
222+
Directory.CreateDirectory(restoreFolder);
223+
}
224+
if (Directory.Exists(restoreFolder) == true)
225+
{
226+
Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
227+
var uniqueFileName = "Recovered_Scene" + unixTimestamp + ".unity";
228+
File.Copy(recoveryFile, Path.Combine(restoreFolder, uniqueFileName));
229+
Console.WriteLine("Recovered crashed scene into: " + restoreFolder);
230+
}
231+
else
232+
{
233+
Console.WriteLine("Error: Failed to create restore folder: " + restoreFolder);
234+
cancelRunningUnity = true;
235+
}
236+
}
237+
else if (result == MessageBoxResult.Cancel) // dont do restore, but run Unity
238+
{
239+
cancelRunningUnity = true;
240+
}
241+
}
242+
return cancelRunningUnity;
243+
}
217244

218245
public static string GetUnityExePath(string version)
219246
{

0 commit comments

Comments
 (0)