@@ -52,17 +52,17 @@ internal SaveGameHelper()
5252 {
5353 zipHelper = new SevenZipHelper ( ) ;
5454 }
55- internal async Task RestoreBackup ( int gameId )
55+ internal async Task < bool > RestoreBackup ( int gameId , string installationDir )
5656 {
5757 if ( ! LoginManager . Instance . IsLoggedIn ( ) || ! SettingsViewModel . Instance . CloudSaves || ! SettingsViewModel . Instance . License . IsActive ( ) )
58- return ;
58+ return false ;
5959
6060 using ( HttpClient client = new HttpClient ( ) )
6161 {
6262 try
6363 {
6464 client . Timeout = TimeSpan . FromSeconds ( 15 ) ;
65- string deviceId = GetDeviceId ( ) ;
65+ string installationId = GetGameInstallationId ( installationDir ) ;
6666 string [ ] auth = WebHelper . GetCredentials ( ) ;
6767 client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( $ "{ auth [ 0 ] } :{ auth [ 1 ] } ") ) ) ;
6868 client . DefaultRequestHeaders . Add ( "User-Agent" , $ "GameVault/{ SettingsViewModel . Instance . Version } ") ;
@@ -71,7 +71,7 @@ internal async Task RestoreBackup(int gameId)
7171 {
7272 response . EnsureSuccessStatusCode ( ) ;
7373 string fileName = response . Content . Headers . ContentDisposition . FileName . Split ( '_' ) [ 1 ] . Split ( '.' ) [ 0 ] ;
74- if ( fileName != deviceId )
74+ if ( fileName != installationId )
7575 {
7676 string tempFolder = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
7777 Directory . CreateDirectory ( tempFolder ) ;
@@ -96,6 +96,7 @@ internal async Task RestoreBackup(int gameId)
9696 process . WaitForExit ( ) ;
9797 ProcessShepherd . Instance . RemoveProcess ( process ) ;
9898 Directory . Delete ( tempFolder , true ) ;
99+ return true ;
99100 }
100101 }
101102 }
@@ -112,16 +113,18 @@ internal async Task RestoreBackup(int gameId)
112113 }
113114 }
114115 }
116+ return false ;
115117 }
116- private string GetDeviceId ( )
118+ private string GetGameInstallationId ( string installationDir )
117119 {
118- string deviceId = Preferences . Get ( AppConfigKey . DeviceId , AppFilePath . UserFile ) ;
119- if ( string . IsNullOrWhiteSpace ( deviceId ) )
120+ string metadataFile = Path . Combine ( installationDir , "gamevault-exec" ) ;
121+ string installationId = Preferences . Get ( AppConfigKey . InstallationId , metadataFile ) ;
122+ if ( string . IsNullOrWhiteSpace ( installationId ) )
120123 {
121- deviceId = Guid . NewGuid ( ) . ToString ( ) ;
122- Preferences . Set ( AppConfigKey . DeviceId , deviceId , AppFilePath . UserFile ) ;
124+ installationId = Guid . NewGuid ( ) . ToString ( ) ;
125+ Preferences . Set ( AppConfigKey . InstallationId , installationId , metadataFile ) ;
123126 }
124- return deviceId ;
127+ return installationId ;
125128 }
126129 internal async Task BackupSaveGamesFromIds ( List < int > gameIds )
127130 {
@@ -135,7 +138,16 @@ internal async Task BackupSaveGamesFromIds(List<int> gameIds)
135138 }
136139 try
137140 {
138- await BackupSaveGame ( removedId ) ;
141+ MainWindowViewModel . Instance . AppBarText = "Uploading Savegame to the Server..." ;
142+ bool success = await BackupSaveGame ( removedId ) ;
143+ if ( success )
144+ {
145+ MainWindowViewModel . Instance . AppBarText = "Successfully synchronized the cloud saves" ;
146+ }
147+ else
148+ {
149+ MainWindowViewModel . Instance . AppBarText = "Failed to upload your Savegame to the Server" ;
150+ }
139151 }
140152 catch ( Exception ex )
141153 {
@@ -149,36 +161,31 @@ internal async Task BackupSaveGamesFromIds(List<int> gameIds)
149161 // Remove IDs that are no longer in the new list
150162 runningGameIds = runningGameIds . Intersect ( gameIds ) . ToList ( ) ;
151163 }
152- internal async Task BackupSaveGame ( int gameId )
164+ internal async Task < bool > BackupSaveGame ( int gameId )
153165 {
154166 if ( ! SettingsViewModel . Instance . License . IsActive ( ) )
155- return ;
167+ return false ;
156168
157- string gameMetadataTitle = FindGameTitleFromInstalledGames ( gameId ) ;
158- if ( gameMetadataTitle != "" )
169+ var installedGame = InstallViewModel . Instance ? . InstalledGames ? . FirstOrDefault ( g => g . Key ? . ID == gameId ) ;
170+ string gameMetadataTitle = installedGame ? . Key ? . Metadata ? . Title ?? "" ;
171+ string installationDir = installedGame ? . Value ?? "" ;
172+ if ( gameMetadataTitle != "" && installationDir != "" )
159173 {
160174 string title = await SearchForLudusaviGameTitle ( gameMetadataTitle ) ;
161175 string tempFolder = await CreateBackup ( title ) ;
162176 string archive = Path . Combine ( tempFolder , "backup.zip" ) ;
163177 if ( Directory . GetFiles ( tempFolder , "mapping.yaml" , SearchOption . AllDirectories ) . Length == 0 )
164178 {
165179 Directory . Delete ( tempFolder , true ) ;
166- return ;
180+ return false ;
167181 }
168182 await zipHelper . PackArchive ( tempFolder , archive ) ;
169183
170- bool success = await UploadSavegame ( archive , gameId ) ;
184+ bool success = await UploadSavegame ( archive , gameId , installationDir ) ;
171185 Directory . Delete ( tempFolder , true ) ;
172- if ( ! success )
173- {
174- MainWindowViewModel . Instance . AppBarText = "Failed to sync your savegame to the cloud." ;
175- }
186+ return success ;
176187 }
177- }
178- private string FindGameTitleFromInstalledGames ( int gameId )
179- {
180- string gameMetadataTitle = InstallViewModel . Instance ? . InstalledGames ? . FirstOrDefault ( g => g . Key ? . ID == gameId ) . Key ? . Metadata ? . Title ?? "" ;
181- return gameMetadataTitle ;
188+ return false ;
182189 }
183190 internal async Task < string > SearchForLudusaviGameTitle ( string title )
184191 {
@@ -232,14 +239,14 @@ private async Task<string> CreateBackup(string lunusaviTitle)
232239 return tempFolder ;
233240 } ) ;
234241 }
235- private async Task < bool > UploadSavegame ( string saveFilePath , int gameId )
242+ private async Task < bool > UploadSavegame ( string saveFilePath , int gameId , string installationDir )
236243 {
237244 try
238245 {
239- string devideId = GetDeviceId ( ) ;
246+ string installationId = GetGameInstallationId ( installationDir ) ;
240247 using ( MemoryStream memoryStream = await FileToMemoryStreamAsync ( saveFilePath ) )
241248 {
242- await WebHelper . UploadFileAsync ( @$ "{ SettingsViewModel . Instance . ServerUrl } /api/savefiles/user/{ LoginManager . Instance . GetCurrentUser ( ) ! . ID } /game/{ gameId } ", memoryStream , "x.zip" , new KeyValuePair < string , string > ( "X-Device -Id" , devideId ) ) ;
249+ await WebHelper . UploadFileAsync ( @$ "{ SettingsViewModel . Instance . ServerUrl } /api/savefiles/user/{ LoginManager . Instance . GetCurrentUser ( ) ! . ID } /game/{ gameId } ", memoryStream , "x.zip" , new KeyValuePair < string , string > ( "X-Installation -Id" , installationId ) ) ;
243250 }
244251 }
245252 catch
0 commit comments