From f2197831e1ab16543e06c34f2b1a3978e07acba8 Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sat, 7 Sep 2024 09:19:32 +0200 Subject: [PATCH 1/8] cloudSyncHealth --- functions/cloudSyncHealth.ps1 | 192 +++++++++++++++++++++------------- 1 file changed, 121 insertions(+), 71 deletions(-) diff --git a/functions/cloudSyncHealth.ps1 b/functions/cloudSyncHealth.ps1 index a19ac8c7..d3c306f3 100644 --- a/functions/cloudSyncHealth.ps1 +++ b/functions/cloudSyncHealth.ps1 @@ -1,84 +1,134 @@ -function cloud_sync_download_test($emuName){ - if ((Test-Path "$cloud_sync_bin") -and ($cloud_sync_status -eq $true)) { - - $target = "$emulationPath\saves\$emuName\" - if ( Test-Path "$target" ){ - "test" | Set-Content "$target\.temp" -ErrorAction SilentlyContinue -Encoding UTF8 - $fileHash = "$target\.temp" - - - & $cloud_sync_bin -q --log-file "$userFolder/EmuDeck/logs/rclone.log" copyto --fast-list --checkers=50 --transfers=50 --low-level-retries 1 --retries 1 "$cloud_sync_provider`:Emudeck\saves\$emuName\.temp" "$fileHash" - if ($?) { - echo "$elemento download Status: Success" - }else{ - echo "$elemento download Status: Failure" - rm -fo -r "$target\.temp" -ErrorAction SilentlyContinue - exit - } - rm -fo -r "$target\.temp" -ErrorAction SilentlyContinue - } +function cloudSyncHealth(){ - } -} + $watcherStatus=1 + $upload=1 + $download=1 -function cloud_sync_upload_test($emuNAme){ - if ((Test-Path "$cloud_sync_bin") -and ($cloud_sync_status -eq $true)) { + $result = yesNoDialog -TitleText "CloudSync Health" -MessageText "Do you use EmulationStation to launch your games?" -OKButtonText "Yes" -CancelButtonText "No" - $target = "$emulationPath\saves\$emuName\" - if ( Test-Path "$target" ){ - "test" | Set-Content "$target\.temp" -ErrorAction SilentlyContinue -Encoding UTF8 - $fileHash = "$target\.temp" + if ($result -eq "OKButton") { + #Launching ESDE + Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$toolsPath/launchers/esde/EmulationStationDE.ps1`" " - & $cloud_sync_bin -q --log-file "$userFolder/EmuDeck/logs/rclone.log" copyto --fast-list --checkers=50 --transfers=50 --low-level-retries 1 --retries 1 "$fileHash" "$cloud_sync_provider`:Emudeck\saves\$emuName\.temp" - if ($?) { - echo "$elemento upload Status: Success" - }else{ - echo "$elemento upload Status: Failure" - rm -fo -r "$target\.temp" -ErrorAction SilentlyContinue - exit - } - rm -fo -r "$target\.temp" -ErrorAction SilentlyContinue - } + } else { + $kill = "RETROARCH" + Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$toolsPath/launchers/retroarch.ps1`" " + } + if ($kill -eq "RETROARCH") { + while (-not (Get-Process -Name "retroarch" -ErrorAction SilentlyContinue)) { + echo "waiting for RA to open" + Start-Sleep -Seconds 2 + } + }else{ + while (-not (Get-Process -Name "ES-DE" -ErrorAction SilentlyContinue)) { + echo "waiting for ESDE to open" + Start-Sleep -Seconds 2 } + } + Start-Sleep -Seconds 2 + echo "Creating test file" + echo "testing upload" > "$savesPath/retroarch/test_emudeck.txt" -} + while (-not (Get-Process -Name "rclone" -ErrorAction SilentlyContinue)) { + echo "waiting for rclone to open" + Start-Sleep -Seconds 1 + } -function cloudSyncHealth(){ - echo "" - echo "" - if ( -not (Test-Path "$toolsPath\rclone\rclone.exe")) { - echo "" - exit - }else{ - echo "" - } - echo "" - if ( -not (Test-Path "$toolsPath\rclone\rclone.conf")) { - echo "" - exit - }else{ - echo "" - } - echo "" - if ( $cloud_sync_provider -eq '') { - echo "" - exit - }else{ - echo "" - } - echo "" - $miArreglo = @("retroarch") + while (Get-Process -Name "rclone" -ErrorAction SilentlyContinue) { + echo "waiting for rclone to finish" + Start-Sleep -Seconds 1 + } - foreach ($elemento in $miArreglo) { - cloud_sync_upload_test $elemento - } + $result = & $cloud_sync_bin lsf "$cloud_sync_provider`:Emudeck/saves/retroarch/" | Select-String "test_emudeck.txt" + + # Evaluar el resultado + if ($result) { + Write-Host "file exists in the cloud. SUCCESS" + $upload = 0 + } else { + Write-Host "file does not exist in the cloud. FAIL" + } + + + # + ##Testing Dowmload + # + + & "$cloud_sync_bin" --progress copyto -L --fast-list --checkers=50 --transfers=50 --low-level-retries 1 --retries 1 "$cloud_sync_provider`:Emudeck/saves/retroarch/test_emudeck.txt" "$savesPath/retroarch/test_emudeck.txt" + + if (Test-Path "$savesPath\retroarch\test_emudeck.txt") { + Write-Host "file exists in local. SUCCESS" + $download = 0 + } else { + Write-Host "file does not exist in local. FAIL" + } + + # Eliminar los directorios y archivos locales + Remove-Item -Recurse -Force "$savesPath\.watching" + Remove-Item -Recurse -Force "$savesPath\retroarch\test_emudeck.txt" + + # Eliminar el archivo remoto + & $cloud_sync_bin delete "$cloud_sync_provider`:Emudeck/saves/retroarch/test_emudeck.txt" + + # Verificar si se debe matar Retroarch o cerrar otra ventana + if ($kill -eq "RETROARCH") { + Stop-Process -Name "RetroArch" -Force + } else { + Stop-Process -Name "ES-DE" -Force + } + + Write-Host "
Executable Status: Failure, please reinstallExecutable Status: Success
Config file Status: Failure, please reinstallConfig file Status: Success
Provider Status: Failure, please reinstallProvider Status: Success
" + Write-Host "" + + # Check installation + if (-Not (Test-Path $cloud_sync_bin)) { + Write-Host "
Executable Status: Failure, please reinstall
" + exit + } else { + Write-Host "Executable Status: Success" + } + Write-Host "" + + if (-Not (Test-Path $cloud_sync_config_file)) { + Write-Host "Config file Status: Failure, please reinstall" + exit + } else { + Write-Host "Config file Status: Success" + } + Write-Host "" + + if ([string]::IsNullOrEmpty($cloud_sync_provider)) { + Write-Host "Provider Status: Failure, please reinstall" + exit + } else { + Write-Host "Provider Status: Success" + } + Write-Host "" + + # Tests upload + Write-Host "" + if ($upload -eq 0) { + Write-Host "Upload Status: Success" + } else { + Write-Host "Upload Status: Failure" + Write-Host "" + } + Write-Host "" + + # Tests download + Write-Host "" + if ($download -eq 0) { + Write-Host "Download Status: Success" + } else { + Write-Host "Download Status: Failure" + Write-Host "" + } + Write-Host "" + + Write-Host "" + Write-Host "" - foreach ($elemento in $miArreglo) { - cloud_sync_download_test $elemento - } - echo "" - Write-Host "" } \ No newline at end of file From 5e6e9fef214a5d69f2a2e693a3d5541ea589a839 Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sat, 7 Sep 2024 09:56:04 +0200 Subject: [PATCH 2/8] hidden info --- functions/cloudSyncHealth.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/functions/cloudSyncHealth.ps1 b/functions/cloudSyncHealth.ps1 index d3c306f3..9de84c93 100644 --- a/functions/cloudSyncHealth.ps1 +++ b/functions/cloudSyncHealth.ps1 @@ -1,5 +1,6 @@ function cloudSyncHealth(){ + Write-Host "" + Write-Host "" Write-Host "" From 975b68dbcba24c3f2b7f2c872717b692c3271722 Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sat, 7 Sep 2024 09:58:42 +0200 Subject: [PATCH 3/8] Write-Host --- tools/cloudSync/cloud_sync_watcher_user.ps1 | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/cloudSync/cloud_sync_watcher_user.ps1 b/tools/cloudSync/cloud_sync_watcher_user.ps1 index 574a3920..cfdbbb73 100644 --- a/tools/cloudSync/cloud_sync_watcher_user.ps1 +++ b/tools/cloudSync/cloud_sync_watcher_user.ps1 @@ -73,7 +73,7 @@ try $skip = $blackList | ForEach-Object { $FullPath -like "*$_" } if($skip -contains $true){ - echo "Ignoring blacklisted file" + Write-Host "Ignoring blacklisted file" return } @@ -86,7 +86,7 @@ try # Check if the file was modified in the last 2 seconds $lastModifiedTime = $lastModifiedTimes[$FullPath] if ($lastModifiedTime -and ($Timestamp).Subtract($lastModifiedTime).TotalMilliseconds -lt 500) { - echo "Ignoring $FullPath because it was modified again too quickly." + Write-Host "Ignoring $FullPath because it was modified again too quickly." return } @@ -103,8 +103,8 @@ try # let's compose a message: $text = "{0} was {1} at {2}" -f $FullPath, $ChangeType, $Timestamp - echo "" - echo $text -ForegroundColor DarkYellow + Write-Host "" + Write-Host $text -ForegroundColor DarkYellow # you can also execute code based on change type here: switch ($ChangeType) @@ -112,7 +112,7 @@ try 'Changed' { if ($skip -contains $true -or $FullPath -eq $savesPath -or $FullPath -eq $emuPath) { - echo "No upload" + Write-Host "No upload" } else { $toast = steamToast -MessageText "CloudSync - Uploading Modified file" Get-Date -Format "yyyy-MM-dd HH:mm:ss" | Out-File -FilePath $savesPath/$emuName/.pending_upload @@ -124,7 +124,7 @@ try } 'Created' { if ($skip -contains $true -or $FullPath -eq $savesPath -or $FullPath -eq $emuPath) { - echo "No upload" + Write-Host "No upload" } else { $toast = steamToast -MessageText "CloudSync - Uploading new file" Get-Date -Format "yyyy-MM-dd HH:mm:ss" | Out-File -FilePath $savesPath/$emuName/.pending_upload @@ -139,18 +139,18 @@ try # to illustrate that ALL changes are picked up even if # handling an event takes a lot of time, we artificially # extend the time the handler needs whenever a file is deleted - echo "Deletion Handler Start" + Write-Host "Deletion Handler Start" Start-Sleep -Seconds 4 - echo "Deletion Handler End" + Write-Host "Deletion Handler End" } 'Renamed' { # this executes only when a file was renamed $text = "File {0} was renamed to {1}" -f $OldName, $Name - echo $text + Write-Host $text } # any unhandled change types surface here: - default { echo $_ } + default { Write-Host $_ } } } @@ -167,7 +167,7 @@ try # monitoring starts now: $watcher.EnableRaisingEvents = $true - echo "Watching for changes to $Path" + Write-Host "Watching for changes to $Path" # since the FileSystemWatcher is no longer blocking PowerShell # we need a way to pause PowerShell while being responsive to @@ -179,7 +179,7 @@ try Wait-Event -Timeout 1 # write a dot to indicate we are still monitoring: - echo "." -NoNewline + Write-Host "." -NoNewline # Process name to find $processName = "EmuDeck Launcher" @@ -192,13 +192,13 @@ try # We exit if it doesn't if (-not (Test-Path $cmdFile)) { - echo "There's no .watching file" + Write-Host "There's no .watching file" $dialog = steamToast -MessageText "Uploading... don't turn off your device" Add-Type -AssemblyName System.speech # Check for lock file if (-not (Test-Path $lockFile)) { $dialog.Close() - echo "There's no lock file, bye!" + Write-Host "There's no lock file, bye!" $dialog = steamToast -MessageText "Sync Completed! You can safely turn off your device" & $nssm stop CloudWatch $dialog.Close() From f336117b7ad0796e127aba8423fa60f68269ff69 Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sat, 7 Sep 2024 10:04:58 +0200 Subject: [PATCH 4/8] +5s --- functions/cloudSyncHealth.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/cloudSyncHealth.ps1 b/functions/cloudSyncHealth.ps1 index 9de84c93..6b5e4c8b 100644 --- a/functions/cloudSyncHealth.ps1 +++ b/functions/cloudSyncHealth.ps1 @@ -28,7 +28,7 @@ function cloudSyncHealth(){ Start-Sleep -Seconds 2 } } - Start-Sleep -Seconds 2 + Start-Sleep -Seconds 5 echo "Creating test file" echo "testing upload" > "$savesPath/retroarch/test_emudeck.txt" From e21e696fe22d16c0cfb15ab5c98cbe2f98d02f78 Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sat, 7 Sep 2024 22:06:19 +0200 Subject: [PATCH 5/8] cloud_sync_force --- functions/ToolScripts/emuDeckSaveSync.ps1 | 10 ++++++++++ tools/cloudSync/cloud_sync_force.bat | 1 + tools/cloudSync/cloud_sync_force.ps1 | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tools/cloudSync/cloud_sync_force.bat create mode 100644 tools/cloudSync/cloud_sync_force.ps1 diff --git a/functions/ToolScripts/emuDeckSaveSync.ps1 b/functions/ToolScripts/emuDeckSaveSync.ps1 index 80aadf3d..afa85c6f 100644 --- a/functions/ToolScripts/emuDeckSaveSync.ps1 +++ b/functions/ToolScripts/emuDeckSaveSync.ps1 @@ -161,6 +161,16 @@ $scriptContent = @" function cloud_sync_install($cloud_sync_provider){ #startLog($MyInvocation.MyCommand.Name) + $batFilePath = "$env:APPDATA\EmuDeck\backend\tools\cloudSync\cloud_sync_force.bat" + $shortcutPath = "$env:USERPROFILE\Desktop\Force CloudSync.lnk" + $iconPath = "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/tools/cloudSync/steamdecklogo.png" + $wshShell = New-Object -ComObject WScript.Shell + $shortcut = $wshShell.CreateShortcut($shortcutPath) + $shortcut.TargetPath = $batFilePath + $shortcut.IconLocation = $iconPath + $shortcut.Save() + + confirmDialog -TitleText "Administrator Privileges needed" -MessageText "During the installation of CloudSync you'll get several windows asking for elevated permissions. This is so we can create symlinks, a background service and set its proper permissions. Please accept all of them" & "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/wintools/nssm.exe" stop "CloudWatch" diff --git a/tools/cloudSync/cloud_sync_force.bat b/tools/cloudSync/cloud_sync_force.bat new file mode 100644 index 00000000..9503b5af --- /dev/null +++ b/tools/cloudSync/cloud_sync_force.bat @@ -0,0 +1 @@ +powershell -ExecutionPolicy Bypass -NoExit . .\cloud_sync_force.ps1 \ No newline at end of file diff --git a/tools/cloudSync/cloud_sync_force.ps1 b/tools/cloudSync/cloud_sync_force.ps1 new file mode 100644 index 00000000..db7b5911 --- /dev/null +++ b/tools/cloudSync/cloud_sync_force.ps1 @@ -0,0 +1,11 @@ +$result = yesNoDialog -TitleText "CloudSync Force" -MessageText "Do you want to force the download or the upload" -OKButtonText "Upload" -CancelButtonText "Download" + +if ($result -eq "OKButton") { + $dialog = steamToast -MessageText "Uploading... don't turn off your device" + cloud_sync_uploadEmuAll + $dialog.Close() +} else { + $dialog = steamToast -MessageText "Downloading... don't turn off your device" + cloud_sync_downloadEmuAll + $dialog.Close() +} \ No newline at end of file From 2f1b3c214779e4ab8879e11e14bca262f2fc586c Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sat, 7 Sep 2024 22:10:11 +0200 Subject: [PATCH 6/8] fixes force CS --- functions/ToolScripts/emuDeckSaveSync.ps1 | 2 +- tools/cloudSync/cloud_sync_force.bat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/ToolScripts/emuDeckSaveSync.ps1 b/functions/ToolScripts/emuDeckSaveSync.ps1 index afa85c6f..3e0b775b 100644 --- a/functions/ToolScripts/emuDeckSaveSync.ps1 +++ b/functions/ToolScripts/emuDeckSaveSync.ps1 @@ -163,7 +163,7 @@ function cloud_sync_install($cloud_sync_provider){ $batFilePath = "$env:APPDATA\EmuDeck\backend\tools\cloudSync\cloud_sync_force.bat" $shortcutPath = "$env:USERPROFILE\Desktop\Force CloudSync.lnk" - $iconPath = "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/tools/cloudSync/steamdecklogo.png" + $iconPath = "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/tools/gamemode/icon.ico" $wshShell = New-Object -ComObject WScript.Shell $shortcut = $wshShell.CreateShortcut($shortcutPath) $shortcut.TargetPath = $batFilePath diff --git a/tools/cloudSync/cloud_sync_force.bat b/tools/cloudSync/cloud_sync_force.bat index 9503b5af..2a9aec13 100644 --- a/tools/cloudSync/cloud_sync_force.bat +++ b/tools/cloudSync/cloud_sync_force.bat @@ -1 +1 @@ -powershell -ExecutionPolicy Bypass -NoExit . .\cloud_sync_force.ps1 \ No newline at end of file +powershell -ExecutionPolicy Bypass -NoExit . %APPDATA%\EmuDeck\backend\tools\cloudSync\cloud_sync_force.ps1 \ No newline at end of file From d4ba6f65d910ea966061848c15a85d5957f473d2 Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sat, 7 Sep 2024 22:10:11 +0200 Subject: [PATCH 7/8] fixes force CS --- functions/ToolScripts/emuDeckSaveSync.ps1 | 3 +-- tools/cloudSync/cloud_sync_force.ps1 | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/ToolScripts/emuDeckSaveSync.ps1 b/functions/ToolScripts/emuDeckSaveSync.ps1 index 3e0b775b..e190b10a 100644 --- a/functions/ToolScripts/emuDeckSaveSync.ps1 +++ b/functions/ToolScripts/emuDeckSaveSync.ps1 @@ -160,10 +160,9 @@ $scriptContent = @" function cloud_sync_install($cloud_sync_provider){ #startLog($MyInvocation.MyCommand.Name) - $batFilePath = "$env:APPDATA\EmuDeck\backend\tools\cloudSync\cloud_sync_force.bat" $shortcutPath = "$env:USERPROFILE\Desktop\Force CloudSync.lnk" - $iconPath = "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/tools/gamemode/icon.ico" + $iconPath = "$env:USERPROFILE/AppData/Local/Programs/EmuDeck/EmuDeck.exe" $wshShell = New-Object -ComObject WScript.Shell $shortcut = $wshShell.CreateShortcut($shortcutPath) $shortcut.TargetPath = $batFilePath diff --git a/tools/cloudSync/cloud_sync_force.ps1 b/tools/cloudSync/cloud_sync_force.ps1 index db7b5911..0cc58395 100644 --- a/tools/cloudSync/cloud_sync_force.ps1 +++ b/tools/cloudSync/cloud_sync_force.ps1 @@ -1,3 +1,4 @@ +. "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/functions/allCloud.ps1" $result = yesNoDialog -TitleText "CloudSync Force" -MessageText "Do you want to force the download or the upload" -OKButtonText "Upload" -CancelButtonText "Download" if ($result -eq "OKButton") { From e32b92f0fc5e04c4e5c05e50449c9c944a73a343 Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sat, 7 Sep 2024 22:33:48 +0200 Subject: [PATCH 8/8] force close Rclone just in case --- functions/ToolScripts/emuDeckSaveSync.ps1 | 3 ++- tools/cloudSync/cloud_sync_force.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/functions/ToolScripts/emuDeckSaveSync.ps1 b/functions/ToolScripts/emuDeckSaveSync.ps1 index e190b10a..a3c91c62 100644 --- a/functions/ToolScripts/emuDeckSaveSync.ps1 +++ b/functions/ToolScripts/emuDeckSaveSync.ps1 @@ -625,7 +625,7 @@ function cloud_sync_downloadEmu($emuName, $mode){ if (Test-Path "$cloud_sync_bin") { #We check for internet connection if ( check_internet_connection -eq 'true' ){ - + Stop-Process -Name "Rclone" -Force -ErrorAction SilentlyContinue #Do we have a pending upload? if (Test-Path "$savesPath/$emuName/.pending_upload") { @@ -709,6 +709,7 @@ function cloud_sync_uploadEmu{ if (Test-Path "$cloud_sync_bin") { #We check for internet connection if ( check_internet_connection -eq 'true' ){ + Stop-Process -Name "Rclone" -Force -ErrorAction SilentlyContinue #Do we have a failed download? if (Test-Path "$savesPath/$emuName/.fail_upload") { $date = Get-Content "$savesPath/$emuName/.fail_upload" diff --git a/tools/cloudSync/cloud_sync_force.ps1 b/tools/cloudSync/cloud_sync_force.ps1 index 0cc58395..da527923 100644 --- a/tools/cloudSync/cloud_sync_force.ps1 +++ b/tools/cloudSync/cloud_sync_force.ps1 @@ -2,11 +2,11 @@ $result = yesNoDialog -TitleText "CloudSync Force" -MessageText "Do you want to force the download or the upload" -OKButtonText "Upload" -CancelButtonText "Download" if ($result -eq "OKButton") { - $dialog = steamToast -MessageText "Uploading... don't turn off your device" + $dialog = steamToast -MessageText "Uploading all systems... don't turn off your device" cloud_sync_uploadEmuAll $dialog.Close() } else { - $dialog = steamToast -MessageText "Downloading... don't turn off your device" + $dialog = steamToast -MessageText "Downloading all systems... don't turn off your device" cloud_sync_downloadEmuAll $dialog.Close() } \ No newline at end of file