Skip to content

Commit 3678466

Browse files
committed
adding git support #218
1 parent 0119466 commit 3678466

6 files changed

Lines changed: 130 additions & 35 deletions

File tree

UnityLauncherPro/NewProject.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
</Button>
7979
</Grid>
8080

81-
<Expander x:Name="expVersionControl" Margin="0,10,0,0" Header="Version Control (Github)" Foreground="{DynamicResource ThemeButtonForeground}" IsExpanded="True" Collapsed="expVersionControl_Collapsed">
81+
<Expander x:Name="expVersionControl" Margin="0,10,0,0" Header="Version Control (Github)" Foreground="{DynamicResource ThemeButtonForeground}" IsExpanded="True" Collapsed="expVersionControl_Collapsed" Expanded="expVersionControl_Collapsed">
8282
<Grid UseLayoutRounding="False">
8383
<StackPanel Margin="0,6,0,0" Orientation="Vertical">
8484
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">

UnityLauncherPro/NewProject.xaml.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public NewProject(string unityVersion, string suggestedName, string targetFolder
8585
gridAvailableVersions.SelectedIndex = i;
8686
gridAvailableVersions.ScrollIntoView(gridAvailableVersions.SelectedItem);
8787

88-
string baseVersion = GetBaseVersion(newVersion);
88+
string baseVersion = Tools.GetBaseVersion(newVersion);
8989
if (fetchOnlineTemplates) _ = LoadOnlineTemplatesAsync(baseVersion);
9090
break;
9191
}
@@ -127,6 +127,12 @@ public NewProject(string unityVersion, string suggestedName, string targetFolder
127127
private void LoadSettings()
128128
{
129129
chkForceDX11.IsChecked = Settings.Default.forceDX11;
130+
chkEnableLfs.IsChecked = Settings.Default.gitIEnableLFS;
131+
chkInitialCommit.IsChecked = Settings.Default.gitInitialCommit;
132+
chkAddReadme.IsChecked = Settings.Default.gitAddReadme;
133+
//chkAddUnityGitIgnore.IsChecked = Settings.Default.gitAddUnityGitIgnore; // not used yet
134+
chkEnableVersionControl.IsChecked = Settings.Default.gitEnableVersionControl;
135+
expVersionControl.IsExpanded = Settings.Default.gitPanelExpanded || Settings.Default.gitEnableVersionControl;
130136
}
131137

132138
void UpdateTemplatesDropDown(string unityPath)
@@ -388,25 +394,14 @@ private void GridAvailableVersions_SelectionChanged(object sender, SelectionChan
388394
listOnlineTemplates.ItemsSource = null; // clear previous items
389395
if (loadOnlineTemplates)
390396
{
391-
string baseVersion = GetBaseVersion(k.Version);
397+
string baseVersion = Tools.GetBaseVersion(k.Version);
392398
// Cancel previous request
393399
_templateLoadCancellation?.Cancel();
394400
_templateLoadCancellation = new CancellationTokenSource();
395401
_ = LoadOnlineTemplatesAsync(baseVersion, _templateLoadCancellation.Token);
396402
}
397403
}
398404

399-
string GetBaseVersion(string version)
400-
{
401-
// e.g. 2020.3.15f1 -> 2020.3
402-
var parts = version.Split('.');
403-
if (parts.Length >= 2)
404-
{
405-
return parts[0] + "." + parts[1];
406-
}
407-
return version;
408-
}
409-
410405
private void GridAvailableVersions_Loaded(object sender, RoutedEventArgs e)
411406
{
412407
// set initial default row color
@@ -463,6 +458,9 @@ private void chkEnableVersionControl_Checked(object sender, RoutedEventArgs e)
463458
chkInitialCommit.IsEnabled = state;
464459
//chkAddUnityGitIgnore.IsEnabled = state; // not used yet
465460
chkAddReadme.IsEnabled = state;
461+
462+
Settings.Default.gitEnableVersionControl = state;
463+
Settings.Default.Save();
466464
}
467465

468466
private void btnBrowseForProjectFolder_Click(object sender, RoutedEventArgs e)
@@ -531,7 +529,6 @@ private void btnCreateMissingFolder_Click(object sender, RoutedEventArgs e)
531529
}
532530
}
533531

534-
// Add this static field to the class (near other static fields)
535532
private static readonly HttpClient _httpClient = new HttpClient();
536533

537534
private async Task LoadOnlineTemplatesAsync(string baseVersion, CancellationToken cancellationToken = default)
@@ -782,8 +779,6 @@ private int FindMatchingBrace(string json, int openBraceIndex)
782779
return -1;
783780
} // FindMatchingBrace
784781

785-
786-
787782
private void listOnlineTemplates_PreviewMouseDown(object sender, MouseButtonEventArgs e)
788783
{
789784
// Get the item that was clicked
@@ -811,7 +806,6 @@ private void listOnlineTemplates_PreviewMouseDown(object sender, MouseButtonEven
811806
}
812807
}
813808

814-
815809
private void listOnlineTemplates_SelectionChanged(object sender, SelectionChangedEventArgs e)
816810
{
817811
if (listOnlineTemplates.SelectedItem is OnlineTemplateItem selectedTemplate)
@@ -932,7 +926,7 @@ private void btnFetchTemplates_Click(object sender, RoutedEventArgs e)
932926
{
933927
if (gridAvailableVersions.SelectedItem is UnityInstallation selectedInstallation)
934928
{
935-
string baseVersion = GetBaseVersion(selectedInstallation.Version);
929+
string baseVersion = Tools.GetBaseVersion(selectedInstallation.Version);
936930
_templateLoadCancellation?.Cancel();
937931
_templateLoadCancellation = new CancellationTokenSource();
938932
_ = LoadOnlineTemplatesAsync(baseVersion, _templateLoadCancellation.Token);
@@ -957,27 +951,38 @@ private void btnAuthorizeToken_Click(object sender, RoutedEventArgs e)
957951

958952
private void chkEnableLfs_Checked(object sender, RoutedEventArgs e)
959953
{
954+
if (isInitializing) return;
960955

956+
Settings.Default.gitIEnableLFS = chkEnableLfs.IsChecked == true;
957+
Settings.Default.Save();
961958
}
962959

963960
private void chkInitialCommit_Checked(object sender, RoutedEventArgs e)
964961
{
962+
if (isInitializing) return;
965963

964+
Settings.Default.gitInitialCommit = chkInitialCommit.IsChecked == true;
965+
Settings.Default.Save();
966966
}
967967

968968
private void chkAddReadme_Checked(object sender, RoutedEventArgs e)
969969
{
970+
if (isInitializing) return;
970971

972+
Settings.Default.gitAddReadme = chkAddReadme.IsChecked == true;
973+
Settings.Default.Save();
971974
}
972975

973976
private void txtRepoName_TextChanged(object sender, TextChangedEventArgs e)
974977
{
975-
// TODO validate repo name with github requirements and show error if invalid AND check if already used
976978
}
977979

978980
private void expVersionControl_Collapsed(object sender, RoutedEventArgs e)
979981
{
980-
// TODO save state of expander to settings AND if version control is enabled, always show expander and disable collapsing
982+
if (isInitializing) return;
983+
984+
Settings.Default.gitPanelExpanded = expVersionControl.IsExpanded;
985+
Settings.Default.Save();
981986
}
982987

983988

UnityLauncherPro/Properties/Settings.Designer.cs

Lines changed: 73 additions & 13 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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,23 @@
166166
<Setting Name="fetchOnlineTemplates" Type="System.Boolean" Scope="User">
167167
<Value Profile="(Default)">True</Value>
168168
</Setting>
169+
<Setting Name="gitIEnableLFS" Type="System.Boolean" Scope="User">
170+
<Value Profile="(Default)">True</Value>
171+
</Setting>
172+
<Setting Name="gitInitialCommit" Type="System.Boolean" Scope="User">
173+
<Value Profile="(Default)">False</Value>
174+
</Setting>
175+
<Setting Name="gitAddReadme" Type="System.Boolean" Scope="User">
176+
<Value Profile="(Default)">False</Value>
177+
</Setting>
178+
<Setting Name="gitPanelExpanded" Type="System.Boolean" Scope="User">
179+
<Value Profile="(Default)">False</Value>
180+
</Setting>
181+
<Setting Name="gitEnableVersionControl" Type="System.Boolean" Scope="User">
182+
<Value Profile="(Default)">False</Value>
183+
</Setting>
184+
<Setting Name="showRecoveredScenePopup" Type="System.Boolean" Scope="User">
185+
<Value Profile="(Default)">True</Value>
186+
</Setting>
169187
</Settings>
170188
</SettingsFile>

UnityLauncherPro/Tools.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,18 @@ internal static bool IsVersionAtLeast(string version, string v)
33123312
return false;
33133313
}
33143314
}
3315+
3316+
public static string GetBaseVersion(string version)
3317+
{
3318+
// e.g. 2020.3.15f1 -> 2020.3
3319+
var parts = version.Split('.');
3320+
if (parts.Length >= 2)
3321+
{
3322+
return parts[0] + "." + parts[1];
3323+
}
3324+
return version;
3325+
}
3326+
33153327
} // class
33163328

33173329
} // namespace

UnityLauncherPro/UnityLauncherPro.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<RootNamespace>UnityLauncherPro</RootNamespace>
1010
<AssemblyName>UnityLauncherPro</AssemblyName>
1111
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12-
<LangVersion>8.0</LangVersion>
12+
<LangVersion>8.0</LangVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1515
<WarningLevel>4</WarningLevel>

0 commit comments

Comments
 (0)