@@ -55,10 +55,13 @@ internal SaveGameHelper()
5555 {
5656 zipHelper = new SevenZipHelper ( ) ;
5757 }
58- internal async Task < bool > RestoreBackup ( int gameId , string installationDir )
58+ internal async Task < CloudSaveStatus > RestoreBackup ( int gameId , string installationDir )
5959 {
60- if ( ! LoginManager . Instance . IsLoggedIn ( ) || ! SettingsViewModel . Instance . CloudSaves || ! SettingsViewModel . Instance . License . IsActive ( ) )
61- return false ;
60+ if ( ! LoginManager . Instance . IsLoggedIn ( ) || ! SettingsViewModel . Instance . License . IsActive ( ) )
61+ return CloudSaveStatus . Failed ;
62+
63+ if ( ! SettingsViewModel . Instance . CloudSaves )
64+ return CloudSaveStatus . SettingDisabled ;
6265
6366 using ( HttpClient client = new HttpClient ( ) )
6467 {
@@ -106,7 +109,11 @@ internal async Task<bool> RestoreBackup(int gameId, string installationDir)
106109 process . WaitForExit ( ) ;
107110 ProcessShepherd . Instance . RemoveProcess ( process ) ;
108111 Directory . Delete ( tempFolder , true ) ;
109- return true ;
112+ return CloudSaveStatus . Success ;
113+ }
114+ else
115+ {
116+ return CloudSaveStatus . UpToDate ;
110117 }
111118 }
112119 }
@@ -123,7 +130,7 @@ internal async Task<bool> RestoreBackup(int gameId, string installationDir)
123130 }
124131 }
125132 }
126- return false ;
133+ return CloudSaveStatus . Failed ;
127134 }
128135 private string GetGameInstallationId ( string installationDir )
129136 {
@@ -141,22 +148,42 @@ internal async Task BackupSaveGamesFromIds(List<int> gameIds)
141148 var removedIds = runningGameIds . Except ( gameIds ) . ToList ( ) ;
142149
143150 foreach ( var removedId in removedIds )
144- {
145- if ( ! LoginManager . Instance . IsLoggedIn ( ) || ! SettingsViewModel . Instance . CloudSaves )
151+ {
152+ if ( ! SettingsViewModel . Instance . CloudSaves || ! SettingsViewModel . Instance . License . IsActive ( ) )
153+ {
154+ break ;
155+ }
156+ if ( ! LoginManager . Instance . IsLoggedIn ( ) )
146157 {
158+ MainWindowViewModel . Instance . AppBarText = "Can not synchronize the cloud saves, because you are offline" ;
147159 break ;
148160 }
149161 try
150162 {
151163 MainWindowViewModel . Instance . AppBarText = "Uploading Savegame to the Server..." ;
152- bool success = await BackupSaveGame ( removedId ) ;
153- if ( success )
154- {
155- MainWindowViewModel . Instance . AppBarText = "Successfully synchronized the cloud saves" ;
156- }
157- else
164+ CloudSaveStatus status = await BackupSaveGame ( removedId ) ;
165+ switch ( status )
158166 {
159- MainWindowViewModel . Instance . AppBarText = "Failed to upload your Savegame to the Server" ;
167+ case CloudSaveStatus . Success :
168+ {
169+ MainWindowViewModel . Instance . AppBarText = "Successfully synchronized the cloud saves" ;
170+ break ;
171+ }
172+ case CloudSaveStatus . BackupCreationFailed :
173+ {
174+ MainWindowViewModel . Instance . AppBarText = "Failed to create a copy of your Savegame" ;
175+ break ;
176+ }
177+ case CloudSaveStatus . BackupUploadFailed :
178+ {
179+ MainWindowViewModel . Instance . AppBarText = "Failed to upload your Savegame to the Server" ;
180+ break ;
181+ }
182+ case CloudSaveStatus . Failed :
183+ {
184+ MainWindowViewModel . Instance . AppBarText = "Something went wrong during the Backup" ;
185+ break ;
186+ }
160187 }
161188 }
162189 catch ( Exception ex )
@@ -171,10 +198,13 @@ internal async Task BackupSaveGamesFromIds(List<int> gameIds)
171198 // Remove IDs that are no longer in the new list
172199 runningGameIds = runningGameIds . Intersect ( gameIds ) . ToList ( ) ;
173200 }
174- internal async Task < bool > BackupSaveGame ( int gameId )
201+ internal async Task < CloudSaveStatus > BackupSaveGame ( int gameId )
175202 {
176- if ( ! SettingsViewModel . Instance . CloudSaves || ! SettingsViewModel . Instance . License . IsActive ( ) )
177- return false ;
203+ if ( ! SettingsViewModel . Instance . CloudSaves )
204+ return CloudSaveStatus . SettingDisabled ;
205+
206+ if ( ! SettingsViewModel . Instance . License . IsActive ( ) )
207+ return CloudSaveStatus . Failed ;
178208
179209 var installedGame = InstallViewModel . Instance ? . InstalledGames ? . FirstOrDefault ( g => g . Key ? . ID == gameId ) ;
180210 string gameMetadataTitle = installedGame ? . Key ? . Metadata ? . Title ?? "" ;
@@ -184,23 +214,24 @@ internal async Task<bool> BackupSaveGame(int gameId)
184214 PrepareConfigFile ( installedGame ? . Value ! , Path . Combine ( AppFilePath . CloudSaveConfigDir , "config.yaml" ) ) ;
185215 string title = await SearchForLudusaviGameTitle ( gameMetadataTitle ) ;
186216 if ( string . IsNullOrEmpty ( title ) )
187- return false ;
217+ return CloudSaveStatus . Failed ;
218+
188219 string tempFolder = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
189220 Directory . CreateDirectory ( tempFolder ) ;
190221 await CreateBackup ( title , tempFolder ) ;
191222 string archive = Path . Combine ( tempFolder , "backup.zip" ) ;
192223 if ( Directory . GetFiles ( tempFolder , "mapping.yaml" , SearchOption . AllDirectories ) . Length == 0 )
193224 {
194225 Directory . Delete ( tempFolder , true ) ;
195- return false ;
226+ return CloudSaveStatus . BackupCreationFailed ;
196227 }
197228 await zipHelper . PackArchive ( tempFolder , archive ) ;
198229
199230 bool success = await UploadSavegame ( archive , gameId , installationDir ) ;
200231 Directory . Delete ( tempFolder , true ) ;
201- return success ;
232+ return success ? CloudSaveStatus . Success : CloudSaveStatus . BackupUploadFailed ;
202233 }
203- return false ;
234+ return CloudSaveStatus . Failed ;
204235 }
205236 public void PrepareConfigFile ( string installationPath , string yamlPath )
206237 {
@@ -371,6 +402,15 @@ private ProcessStartInfo CreateProcessHeader(bool redirectConsole = false)
371402 return info ;
372403 }
373404 }
405+ public enum CloudSaveStatus
406+ {
407+ Success ,
408+ Failed ,
409+ UpToDate ,
410+ SettingDisabled ,
411+ BackupCreationFailed ,
412+ BackupUploadFailed
413+ }
374414 public class LudusaviManifestEntry
375415 {
376416 public string Uri { get ; set ; }
0 commit comments