@@ -14,15 +14,18 @@ namespace Installer;
1414
1515public static class Installation
1616{
17- private const uint steps = 9 ;
17+ private const string _sourceName = "rbxcs" ;
18+ private const string _sourceURL = "https://nuget.pkg.github.com/roblox-csharp/index.json" ;
19+ private const uint _steps = 9 ;
1820
19- private static readonly float _step = ( 1f / steps ) * 100 ;
21+ private static readonly float _step = ( 1f / _steps ) * 100 ;
2022 private static float _progress = 0 ;
2123 private static Action < int > ? _updateProgress ;
2224 private static Action < string > ? _updateTitle ;
2325 private static Action ? _markErrored ;
2426 private static bool _errored = false ;
2527 private static string _path = "" ;
28+ private static string _latestTag = "" ;
2629
2730 public static async Task InstallRbxcs (
2831 Action < int > updateProgress ,
@@ -36,9 +39,6 @@ string path
3639 _markErrored = markErrored ;
3740 _path = path ;
3841
39- // if (OperatingSystem.IsWindows() && !IsAdmin())
40- // ShowErrorMessageBox($"Cannot install. You are not running with elevated privileges.\nRestart the app as an administrator and try again.");
41-
4242 if ( _errored ) return ;
4343 Display ( "Creating installation environment..." ) ;
4444
@@ -95,37 +95,43 @@ string path
9595 StepProgress ( ) ;
9696
9797 Display ( "Fetching latest release..." ) ;
98- var latestTag = ExecuteGitCommand ( "describe --tags --abbrev=0" , "Failed to get the latest release tag" ) ;
98+ _latestTag = ExecuteGitCommand ( "describe --tags --abbrev=0" , "Failed to get the latest release tag" ) ;
9999 StepProgress ( ) ;
100100
101101 Display ( "Checking out latest release..." ) ;
102- ExecuteGitCommand ( $ "checkout { latestTag } ", "Failed to checkout the latest release" ) ;
102+ ExecuteGitCommand ( $ "checkout { _latestTag } ", "Failed to checkout the latest release" ) ;
103103 StepProgress ( ) ;
104104
105105 Display ( "Building roblox-cs..." ) ;
106+ var sourcesResult = ExecuteCommand ( null , "dotnet" , $ "nuget list source") ;
107+ var sources = sourcesResult . StandardOutput ;
108+ var sourceAlreadyAdded = sources . Contains ( _sourceName ) && sources . Contains ( _sourceURL ) ;
106109 await Dispatcher . UIThread . InvokeAsync ( ( ) =>
107110 {
108- var credentialsWindow = new SourceCredentialsWindow ( )
111+ new SourceCredentialsWindow ( sourceAlreadyAdded )
109112 {
110113 DataContext = new SourceCredentialsWindowViewModel ( )
111114 } ;
112- credentialsWindow . Show ( ) ;
113115 } ) ;
114116 }
115117
116- public static void OnCredentialsAcquired ( SourceCredentialsWindow credentialsWindow )
118+ public static void OnCredentialsAcquired ( SourceCredentialsWindow credentialsWindow , bool sourceAlreadyAdded )
117119 {
118- var usernameTextBox = credentialsWindow . FindControl < TextBox > ( "UsernameBox" ) ! ;
119- var tokenTextBox = credentialsWindow . FindControl < TextBox > ( "TokenBox" ) ! ;
120- Display ( "Adding NuGet source for RobloxCS packages..." ) ;
121- ExecuteCommand ( null , "dotnet" , $ "nuget add source \" https://nuget.pkg.github.com/roblox-csharp/index.json\" -u { usernameTextBox . Text } -p { tokenTextBox . Text } -n github") ;
122- StepProgress ( ) ;
120+ if ( ! sourceAlreadyAdded )
121+ {
122+ // add the source
123+ var usernameTextBox = credentialsWindow . FindControl < TextBox > ( "UsernameBox" ) ! ;
124+ var tokenTextBox = credentialsWindow . FindControl < TextBox > ( "TokenBox" ) ! ;
125+ Display ( "Adding NuGet source for RobloxCS packages..." ) ;
126+ ExecuteCommand ( null , "dotnet" , $ "nuget add source \" { _sourceURL } \" -u { usernameTextBox . Text } -p { tokenTextBox . Text } -n { _sourceName } ") ;
127+ StepProgress ( ) ;
128+ }
123129
124130 Display ( "Compiling..." ) ;
125131 ExecuteCommand ( "Failed to compile roblox-cs" , "dotnet" , "build -c Release" ) ;
126132 StepProgress ( ) ;
127133
128- Display ( "Successfully built roblox-cs." ) ;
134+ Display ( "Successfully compiled roblox-cs." ) ;
129135 if ( OperatingSystem . IsWindows ( ) )
130136 {
131137 UpdateEnvironmentPath ( _path ) ;
@@ -137,7 +143,7 @@ public static void OnCredentialsAcquired(SourceCredentialsWindow credentialsWind
137143 Display ( "Successfully added roblox-cs to your PATH." ) ;
138144
139145 StepProgress ( ) ;
140- Display ( "Successfully installed roblox-cs." ) ;
146+ Display ( $ "Successfully installed roblox-cs ( { _latestTag } ) .") ;
141147 }
142148
143149 private static void UpdateEnvironmentPath ( string path )
@@ -216,8 +222,9 @@ private static ProcessResult ExecuteCommand(string? errorMessage, string command
216222 } ;
217223
218224 if ( result . ExitCode != 0 && errorMessage != null )
225+ {
219226 ShowErrorMessageBox ( $ "{ errorMessage } : { ( ! string . IsNullOrEmpty ( result . StandardError ) ? result . StandardError : result . StandardOutput ) } ") ;
220-
227+ }
221228 return result ;
222229 }
223230
0 commit comments