Skip to content

Commit de6b543

Browse files
committed
Don't ask the user to quit Uplay if cloud sync is already disabled
1 parent c8930b5 commit de6b543

File tree

2 files changed

+59
-54
lines changed

2 files changed

+59
-54
lines changed

src/GHOSTbackup/Form1.vb

+3-54
Original file line numberDiff line numberDiff line change
@@ -302,62 +302,11 @@ Public Class Form1
302302
Banner.Show(64, "You must quit Wildlands before restoring a backup.")
303303
ElseIf IsGameRunning = False And DisableCloudSyncChkBox.Checked = True Then
304304
'If the game is not running and "Let GHOST Buster disable cloud save synchronization" is checked
305-
'Check if Uplay is running or not before editing its settings file
306-
Dim UplayProc = Process.GetProcessesByName("upc")
307-
If UplayProc.Count > 0 Then
308-
CustomMsgBox.Show("{\rtf1 You must {\b quit Uplay before restoring a backup} because you chose to let GHOST Buster disable cloud save synchronization for you.}", "Cannot restore", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
309-
Else
310-
'Disable Uplay cloud save synchronization
311-
Try
312-
Dim UplayYAMLPath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Ubisoft Game Launcher\settings.yml"
313-
Logger.Log("[INFO] Parsing and evaluating Uplay settings file: " & UplayYAMLPath)
314-
Dim ParsedUplayYAML As String = File.ReadAllText(UplayYAMLPath)
315-
316-
If ParsedUplayYAML.Contains("syncsavegames: true") Then
317-
'Backup Uplay settings file
318-
Logger.Log("[INFO] Backing up Uplay settings file to " & UplayYAMLPath & ".bak")
319-
File.Copy(UplayYAMLPath, UplayYAMLPath & ".bak", False) 'Don't overwrite the backup file in the future
320-
321-
'Set syncsavegames to false (Disable cloud save sync)
322-
Dim ReplacedUplayYAML As String = ParsedUplayYAML.Replace("syncsavegames: true", "syncsavegames: false")
323-
File.WriteAllText(UplayYAMLPath, ReplacedUplayYAML)
324-
Logger.Log("[INFO] Uplay cloud save synchronization disabled.")
325-
326-
'Launch Uplay again...
327-
If UplayPath <> Nothing Then
328-
Process.Start(UplayPath & "Uplay.exe")
329-
End If
330-
331-
'...and restore the backup
332-
RestoreBackup()
333-
ElseIf ParsedUplayYAML.Contains("syncsavegames: false") Then
334-
'Don't replace anything if syncsavegames is already set to false
335-
Logger.Log("[INFO] Uplay cloud synchronization is already disabled.")
336-
337-
'Launch Uplay again...
338-
If UplayPath <> Nothing Then
339-
Process.Start(UplayPath & "Uplay.exe")
340-
End If
341-
342-
'...and restore the backup
343-
RestoreBackup()
344-
End If
345-
346-
Catch ex As Exception
347-
'Don't let GHOST Buster disable cloud save sync until the user enables the setting again...
348-
DisableCloudSyncChkBox.Checked = False
349-
'...notify the user about the error
350-
Logger.Log("[ERROR] Parsing of ""settings.yml"" failed: " & ex.Message())
351-
CustomMsgBox.Show("{\rtf1 ""Let GHOST Buster disable cloud save synchronization"" setting has been {\b disabled because an error occurred} while trying to parse Uplay settings file." _
352-
& "\line\line Make sure to {\b DISABLE} cloud save synchronization from Uplay (Settings -> Untick ""Enable cloud save synchronization for supported games"") before launching Wildlands, otherwise the restored save games will be " _
353-
& "{\b OVERWRITTEN} with the old ones from the cloud!",
354-
"Parsing failed", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
355-
'...and proceed with the restore process anyway
356-
RestoreBackup()
357-
End Try
358-
End If
305+
'Disable Uplay cloud save synchronization
306+
DisableCloudSync()
359307
ElseIf IsGameRunning = False And DisableCloudSyncChkBox.Checked = False Then
360308
'If the game is not running and "Let GHOST Buster disable cloud save synchronization" is not checked
309+
'Start the backup process
361310
RestoreBackup()
362311
End If
363312
End Sub

src/GHOSTbackup/GHOSTbackup.Helpers/UplayHelper.vb

+56
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Imports Microsoft.Win32
2+
Imports System.IO
3+
Imports GHOSTbackup.BackupHelper
24
Imports GHOSTbackup.Var
35

46
Public Class UplayHelper
@@ -19,4 +21,58 @@ Public Class UplayHelper
1921
End Try
2022
End Using
2123
End Sub
24+
25+
Public Shared Sub DisableCloudSync()
26+
'Disable Uplay cloud save synchronization
27+
Try
28+
Dim UplayYamlPath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Ubisoft Game Launcher\settings.yml"
29+
Logger.Log("[INFO] Parsing and evaluating Uplay settings file: " & UplayYamlPath)
30+
Dim ParsedUplayYaml As String = File.ReadAllText(UplayYamlPath)
31+
32+
If ParsedUplayYaml.Contains("syncsavegames: true") Then
33+
'If cloud save sync is enabled
34+
'Check if Uplay is running or not before editing its settings file
35+
Dim UplayProc = Process.GetProcessesByName("upc")
36+
If UplayProc.Count > 0 Then
37+
CustomMsgBox.Show("{\rtf1 You must {\b quit Uplay before restoring a backup} because you chose to let GHOST Buster disable cloud save synchronization for you.}", "Cannot restore", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
38+
Else
39+
'Backup Uplay settings file without overwriting an existing backup
40+
Logger.Log("[INFO] Backing up Uplay settings file to " & UplayYamlPath & ".bak")
41+
File.Copy(UplayYamlPath, UplayYamlPath & ".bak", False)
42+
43+
'Disable cloud save sync
44+
Dim ReplacedUplayYaml As String = ParsedUplayYaml.Replace("syncsavegames: true", "syncsavegames: false")
45+
File.WriteAllText(UplayYamlPath, ReplacedUplayYaml)
46+
Logger.Log("[INFO] Uplay cloud save synchronization disabled.")
47+
48+
'Launch Uplay again...
49+
If UplayPath <> Nothing Then
50+
Process.Start(UplayPath & "Uplay.exe")
51+
End If
52+
53+
'...and start the restore process
54+
RestoreBackup()
55+
End If
56+
Else
57+
'Don't replace anything
58+
Logger.Log("[INFO] Uplay cloud synchronization is already disabled.")
59+
60+
'Start the restore process
61+
RestoreBackup()
62+
End If
63+
64+
Catch ex As Exception
65+
'Don't let GHOST Buster disable cloud save sync until the user enables the setting again
66+
Form1.DisableCloudSyncChkBox.Checked = False
67+
68+
Logger.Log("[ERROR] Parsing of ""settings.yml"" failed: " & ex.Message())
69+
CustomMsgBox.Show("{\rtf1 ""Let GHOST Buster disable cloud save synchronization"" setting has been {\b disabled because an error occurred} while trying to parse Uplay settings file." _
70+
& "\line\line Make sure to {\b DISABLE} cloud save synchronization from Uplay (Settings -> Untick ""Enable cloud save synchronization for supported games"") before launching Wildlands, otherwise the restored save games will be " _
71+
& "{\b OVERWRITTEN} with the old ones from the cloud!",
72+
"Parsing failed", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
73+
74+
'Start the restore process anyway
75+
RestoreBackup()
76+
End Try
77+
End Sub
2278
End Class

0 commit comments

Comments
 (0)