Skip to content

Commit

Permalink
Merge branch 'early-unstable' into early
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoonDorise committed Sep 7, 2024
2 parents dcf3508 + 8b55551 commit c36a0e0
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 86 deletions.
12 changes: 11 additions & 1 deletion functions/ToolScripts/emuDeckSaveSync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ $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/Local/Programs/EmuDeck/EmuDeck.exe"
$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"

Expand Down Expand Up @@ -616,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") {

Expand Down Expand Up @@ -700,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"
Expand Down
195 changes: 124 additions & 71 deletions functions/cloudSyncHealth.ps1
Original file line number Diff line number Diff line change
@@ -1,84 +1,137 @@
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 "<tr><td>$elemento download Status: </td><td class='alert--success'><strong>Success</strong></td></tr>"
}else{
echo "<tr><td>$elemento download Status: </td><td class='alert--danger'><strong>Failure</strong></td></tr>"
rm -fo -r "$target\.temp" -ErrorAction SilentlyContinue
exit
}
rm -fo -r "$target\.temp" -ErrorAction SilentlyContinue
}
function cloudSyncHealth(){

}
}
Write-Host "<div class='is-hidden'>"
$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 "<tr><td>$elemento upload Status: </td><td class='alert--success'><strong>Success</strong></td></tr>"
}else{
echo "<tr><td>$elemento upload Status: </td><td class='alert--danger'><strong>Failure</strong></td></tr>"
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 5
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 "<table class='table'>"
echo "<tr>"
if ( -not (Test-Path "$toolsPath\rclone\rclone.exe")) {
echo "<td>Executable Status: </td><td class='alert--danger'><strong>Failure, please reinstall</strong></td>"
exit
}else{
echo "<td>Executable Status: </td><td class='alert--success'><strong>Success</strong></td>"
}
echo "</tr><tr>"
if ( -not (Test-Path "$toolsPath\rclone\rclone.conf")) {
echo "<td>Config file Status: </td><td class='alert--danger'><strong>Failure, please reinstall</strong></td>"
exit
}else{
echo "<td>Config file Status: </td><td class='alert--success'><strong>Success</strong></td>"
}
echo "</tr><tr>"
if ( $cloud_sync_provider -eq '') {
echo "<td>Provider Status: </td><td class='alert--danger'><strong>Failure, please reinstall</strong></td>"
exit
}else{
echo "<td>Provider Status: </td><td class='alert--success'><strong>Success</strong></td>"
}
echo "</tr>"
$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 "</div>"

Write-Host "<table class='table'>"
Write-Host "<tr>"

# Check installation
if (-Not (Test-Path $cloud_sync_bin)) {
Write-Host "<td>Executable Status: </td><td class='alert--danger'><strong>Failure, please reinstall</strong></td></tr></table>"
exit
} else {
Write-Host "<td>Executable Status: </td><td class='alert--success'><strong>Success</strong></td>"
}
Write-Host "</tr><tr>"

if (-Not (Test-Path $cloud_sync_config_file)) {
Write-Host "<td>Config file Status: </td><td class='alert--danger'><strong>Failure, please reinstall</strong></td></tr></table>"
exit
} else {
Write-Host "<td>Config file Status: </td><td class='alert--success'><strong>Success</strong></td>"
}
Write-Host "</tr><tr>"

if ([string]::IsNullOrEmpty($cloud_sync_provider)) {
Write-Host "<td>Provider Status: </td><td class='alert--danger'><strong>Failure, please reinstall</strong></td></tr></table>"
exit
} else {
Write-Host "<td>Provider Status: </td><td class='alert--success'><strong>Success</strong></td>"
}
Write-Host "</tr><tr>"

# Tests upload
Write-Host "<tr>"
if ($upload -eq 0) {
Write-Host "<td>Upload Status: </td><td class='alert--success'><strong>Success</strong></td>"
} else {
Write-Host "<td>Upload Status: </td><td class='alert--danger'><strong>Failure</strong></td>"
Write-Host "</tr></table>"
}
Write-Host "</tr>"

# Tests download
Write-Host "<tr>"
if ($download -eq 0) {
Write-Host "<td>Download Status: </td><td class='alert--success'><strong>Success</strong></td>"
} else {
Write-Host "<td>Download Status: </td><td class='alert--danger'><strong>Failure</strong></td>"
Write-Host "</tr></table>"
}
Write-Host "</tr>"

Write-Host "</table>"
Write-Host "<span class='is-hidden'>true</span>"

foreach ($elemento in $miArreglo) {
cloud_sync_download_test $elemento
}
echo "<td></table>"
Write-Host "<span class='is-hidden'>true</span>"

}
1 change: 1 addition & 0 deletions tools/cloudSync/cloud_sync_force.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
powershell -ExecutionPolicy Bypass -NoExit . %APPDATA%\EmuDeck\backend\tools\cloudSync\cloud_sync_force.ps1
12 changes: 12 additions & 0 deletions tools/cloudSync/cloud_sync_force.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
. "$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") {
$dialog = steamToast -MessageText "Uploading all systems... don't turn off your device"
cloud_sync_uploadEmuAll
$dialog.Close()
} else {
$dialog = steamToast -MessageText "Downloading all systems... don't turn off your device"
cloud_sync_downloadEmuAll
$dialog.Close()
}
28 changes: 14 additions & 14 deletions tools/cloudSync/cloud_sync_watcher_user.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -103,16 +103,16 @@ 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)
{
'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
Expand All @@ -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
Expand All @@ -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 $_ }
}
}

Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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()
Expand Down

0 comments on commit c36a0e0

Please sign in to comment.