77using Avalonia . Media ;
88using Avalonia . Platform . Storage ;
99using MsBox . Avalonia ;
10- using MsBox . Avalonia . Enums ;
1110
1211namespace UnityHubNative . Net ;
1312
@@ -17,14 +16,15 @@ sealed class CreateNewProjectDialogue : Window
1716 TextBox _nameTextBox ;
1817 ComboBox _versionSelector ;
1918 ListBox _templatesParent ;
20- private Button _createButton ;
19+ Button _createButton ;
2120
2221 public CreateNewProjectDialogue ( )
2322 {
2423 Title = "Create a New Unity Project" ;
2524 Content = CreateContent ( ) ;
2625 UpdateVersionSelectionViews ( ) ;
2726 UpdateTemplateViews ( ) ;
27+ UpdateCreateButtonView ( ) ;
2828
2929 SizeToContent = SizeToContent . WidthAndHeight ;
3030 WindowStartupLocation = WindowStartupLocation . CenterOwner ;
@@ -77,7 +77,7 @@ protected override async void OnOpened(EventArgs e)
7777 MaxLines = 1 ,
7878 VerticalAlignment = VerticalAlignment . Center ,
7979 Watermark = "New Unity Project"
80- } ,
80+ } . OnTextChanged ( UpdateCreateButtonView ) ,
8181 ] ) . SetDock ( Dock . Top ) ,
8282 new DockPanel
8383 {
@@ -100,7 +100,7 @@ protected override async void OnOpened(EventArgs e)
100100 MaxLines = 1 ,
101101 VerticalAlignment = VerticalAlignment . Center ,
102102 Watermark = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile )
103- } ,
103+ } . OnTextChanged ( UpdateCreateButtonView ) ,
104104 ] ) . SetDock ( Dock . Top ) ,
105105 new Separator
106106 {
@@ -153,33 +153,48 @@ protected override async void OnOpened(EventArgs e)
153153 ] ) ;
154154 }
155155
156- void OnCreateClicked ( )
156+ async void OnCreateClicked ( )
157157 {
158158 if ( TryGetSelectedUnityInstallation ( out var installation ) )
159159 {
160160 try
161161 {
162- Task . Run ( ( ) => Process . Start ( new ProcessStartInfo
162+ var unityInstallation = UnityHubUtils . UnityInstallations [ _versionSelector . SelectedIndex ] ;
163+ string templatePath = unityInstallation . GetTemplatePaths ( ) [ _templatesParent . SelectedIndex ] ;
164+ string projectPath = Path . Combine ( _pathTextBox . Text ! , _nameTextBox . Text ! ) ;
165+ string args = $ "-createProject \" { projectPath } \" -cloneFromTemplate \" { templatePath } \" ";
166+ var startInfo = new ProcessStartInfo
163167 {
164168 FileName = installation . path ,
165- Arguments = $ "-createProject \" { _pathTextBox } \" -cloneFromTemplate \" { UnityHubUtils . UnityInstallations [ _templatesParent . SelectedIndex ] . path } \" " ,
169+ Arguments = args ,
166170 UseShellExecute = false ,
167171 RedirectStandardOutput = true ,
168172 RedirectStandardError = true ,
169173 CreateNoWindow = true
170- } ) ) ;
171- Close ( ) ;
174+ } ;
175+
176+ _ = Task . Run ( ( ) => Process . Start ( startInfo ) ) ;
177+
178+ UnityHubUtils . UnityProjects . Add ( new ( projectPath , DateTime . UtcNow , unityInstallation ) ) ;
179+ UnityHubUtils . SaveUnityProjects ( ) ;
180+ MainWindow . UpdateUnityProjectViews ( ) ;
172181 }
173- catch ( Exception ex )
182+ catch ( Exception exception )
174183 {
175- MessageBoxManager . GetMessageBoxStandard ( "Cannot Create Project" , $ "Cannot create project at { _pathTextBox } because an error occurred: { ex . Message } " , ButtonEnum . Ok , MsBox . Avalonia . Enums . Icon . Error ) . ShowAsync ( ) ;
184+ Debug . WriteLine ( exception . Message ) ;
176185 }
186+
187+ Close ( ) ;
177188 }
178189 }
179190
180191 void OnCancelClicked ( ) => Close ( ) ;
181192
182- void OnVersionSelectionChanged ( ) => UpdateTemplateViews ( ) ;
193+ void OnVersionSelectionChanged ( )
194+ {
195+ UpdateTemplateViews ( ) ;
196+ UpdateCreateButtonView ( ) ;
197+ }
183198
184199 void UpdateVersionSelectionViews ( )
185200 {
@@ -196,7 +211,6 @@ void UpdateTemplateViews()
196211 if ( TryGetSelectedUnityInstallation ( out var installation ) )
197212 foreach ( var path in installation . GetTemplatePaths ( ) )
198213 _templatesParent . Items . Add ( Path . GetFileName ( path ) ) ;
199- UpdateCreateButtonView ( ) ;
200214 }
201215
202216 void UpdateCreateButtonView ( ) => _createButton . IsEnabled = _templatesParent . Items . Count > 0 && Directory . Exists ( _pathTextBox . Text ) && _nameTextBox . Text ? . Length > 0 ;
0 commit comments