7
7
using Avalonia . Media ;
8
8
using Avalonia . Platform . Storage ;
9
9
using MsBox . Avalonia ;
10
- using MsBox . Avalonia . Enums ;
11
10
12
11
namespace UnityHubNative . Net ;
13
12
@@ -17,14 +16,15 @@ sealed class CreateNewProjectDialogue : Window
17
16
TextBox _nameTextBox ;
18
17
ComboBox _versionSelector ;
19
18
ListBox _templatesParent ;
20
- private Button _createButton ;
19
+ Button _createButton ;
21
20
22
21
public CreateNewProjectDialogue ( )
23
22
{
24
23
Title = "Create a New Unity Project" ;
25
24
Content = CreateContent ( ) ;
26
25
UpdateVersionSelectionViews ( ) ;
27
26
UpdateTemplateViews ( ) ;
27
+ UpdateCreateButtonView ( ) ;
28
28
29
29
SizeToContent = SizeToContent . WidthAndHeight ;
30
30
WindowStartupLocation = WindowStartupLocation . CenterOwner ;
@@ -77,7 +77,7 @@ protected override async void OnOpened(EventArgs e)
77
77
MaxLines = 1 ,
78
78
VerticalAlignment = VerticalAlignment . Center ,
79
79
Watermark = "New Unity Project"
80
- } ,
80
+ } . OnTextChanged ( UpdateCreateButtonView ) ,
81
81
] ) . SetDock ( Dock . Top ) ,
82
82
new DockPanel
83
83
{
@@ -100,7 +100,7 @@ protected override async void OnOpened(EventArgs e)
100
100
MaxLines = 1 ,
101
101
VerticalAlignment = VerticalAlignment . Center ,
102
102
Watermark = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile )
103
- } ,
103
+ } . OnTextChanged ( UpdateCreateButtonView ) ,
104
104
] ) . SetDock ( Dock . Top ) ,
105
105
new Separator
106
106
{
@@ -153,33 +153,48 @@ protected override async void OnOpened(EventArgs e)
153
153
] ) ;
154
154
}
155
155
156
- void OnCreateClicked ( )
156
+ async void OnCreateClicked ( )
157
157
{
158
158
if ( TryGetSelectedUnityInstallation ( out var installation ) )
159
159
{
160
160
try
161
161
{
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
163
167
{
164
168
FileName = installation . path ,
165
- Arguments = $ "-createProject \" { _pathTextBox } \" -cloneFromTemplate \" { UnityHubUtils . UnityInstallations [ _templatesParent . SelectedIndex ] . path } \" " ,
169
+ Arguments = args ,
166
170
UseShellExecute = false ,
167
171
RedirectStandardOutput = true ,
168
172
RedirectStandardError = true ,
169
173
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 ( ) ;
172
181
}
173
- catch ( Exception ex )
182
+ catch ( Exception exception )
174
183
{
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 ) ;
176
185
}
186
+
187
+ Close ( ) ;
177
188
}
178
189
}
179
190
180
191
void OnCancelClicked ( ) => Close ( ) ;
181
192
182
- void OnVersionSelectionChanged ( ) => UpdateTemplateViews ( ) ;
193
+ void OnVersionSelectionChanged ( )
194
+ {
195
+ UpdateTemplateViews ( ) ;
196
+ UpdateCreateButtonView ( ) ;
197
+ }
183
198
184
199
void UpdateVersionSelectionViews ( )
185
200
{
@@ -196,7 +211,6 @@ void UpdateTemplateViews()
196
211
if ( TryGetSelectedUnityInstallation ( out var installation ) )
197
212
foreach ( var path in installation . GetTemplatePaths ( ) )
198
213
_templatesParent . Items . Add ( Path . GetFileName ( path ) ) ;
199
- UpdateCreateButtonView ( ) ;
200
214
}
201
215
202
216
void UpdateCreateButtonView ( ) => _createButton . IsEnabled = _templatesParent . Items . Count > 0 && Directory . Exists ( _pathTextBox . Text ) && _nameTextBox . Text ? . Length > 0 ;
0 commit comments