From 59a929686213752fe55afab07b7cb431802cb754 Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Sun, 11 Aug 2024 01:29:34 +0200 Subject: [PATCH] Revert "testing new cloudsync" This reverts commit bb0413cee3b646902c0e82b7a7159e26c4b04859. --- functions/ToolScripts/emuDeckSaveSync.ps1 | 9 +- functions/emulatorInit.ps1 | 5 +- tools/cloudSync/cloud_sync_watcher_user.ps1 | 220 -------------------- 3 files changed, 6 insertions(+), 228 deletions(-) delete mode 100644 tools/cloudSync/cloud_sync_watcher_user.ps1 diff --git a/functions/ToolScripts/emuDeckSaveSync.ps1 b/functions/ToolScripts/emuDeckSaveSync.ps1 index 9a99d359..3d962177 100644 --- a/functions/ToolScripts/emuDeckSaveSync.ps1 +++ b/functions/ToolScripts/emuDeckSaveSync.ps1 @@ -842,12 +842,11 @@ function cloud_sync_init($emulator){ }else{ "$emulator" | Set-Content $savesPath/.emulator -Encoding UTF8 } - Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$env:USERPROFILE/AppData/Roaming/EmuDeck/tools/cloudSync/cloud_sync_watcher_user.ps1`" $env:USERNAME" -WindowStyle Hidden - #& "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/wintools/nssm.exe" stop "CloudWatch" - #cls - #Start-Process "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/wintools/nssm.exe" -Args "start CloudWatch" -WindowStyle Hidden - #cls + & "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/wintools/nssm.exe" stop "CloudWatch" + cls + Start-Process "$env:USERPROFILE/AppData/Roaming/EmuDeck/backend/wintools/nssm.exe" -Args "start CloudWatch" -WindowStyle Hidden + cls $toast.Close() } } diff --git a/functions/emulatorInit.ps1 b/functions/emulatorInit.ps1 index 79669519..c24671e3 100644 --- a/functions/emulatorInit.ps1 +++ b/functions/emulatorInit.ps1 @@ -22,11 +22,10 @@ function emulatorInit($emuName, $emulatorFile, $formattedArgs){ if($formattedArgs){ #$formattedArgs += "`"$netplayCMD`"" - $process = Start-Process $emulatorFile -PassThru -WindowStyle Maximized -Wait -Args $formattedArgs + Start-Process $emulatorFile -WindowStyle Maximized -Wait -Args $formattedArgs }else{ - $process = Start-Process $emulatorFile -PassThru -WindowStyle Maximized -Wait + Start-Process $emulatorFile -WindowStyle Maximized -Wait } - $process.WaitForExit() rm -fo -r "$savesPath/.watching" -ErrorAction SilentlyContinue rm -fo -r "$savesPath/.emulator" -ErrorAction SilentlyContinue } \ No newline at end of file diff --git a/tools/cloudSync/cloud_sync_watcher_user.ps1 b/tools/cloudSync/cloud_sync_watcher_user.ps1 deleted file mode 100644 index 9139829c..00000000 --- a/tools/cloudSync/cloud_sync_watcher_user.ps1 +++ /dev/null @@ -1,220 +0,0 @@ -$user=$args[0] -$userPath = ( Get-CimInstance Win32_UserProfile -Filter "SID = '$((Get-LocalUser $user).Sid)'" ).LocalPath -$logPath = Join-Path -Path "$userPath" -ChildPath 'EmuDeck\logs\cloudWatcher.log' -$f1 = Join-Path -Path "$userPath" -ChildPath 'EmuDeck\settings.ps1' -$f2 = Join-Path -Path "$userPath" -ChildPath 'AppData\Roaming\EmuDeck\backend\functions\createLink.ps1' -$f3 = Join-Path -Path "$userPath" -ChildPath 'AppData\Roaming\EmuDeck\backend\functions\createLauncher.ps1' -$f4 = Join-Path -Path "$userPath" -ChildPath 'AppData\Roaming\EmuDeck\backend\functions\helperFunctions.ps1' -$f5 = Join-Path -Path "$userPath" -ChildPath 'AppData\Roaming\EmuDeck\backend\functions\ToolScripts\emuDeckSaveSync.ps1' - -$string = "Starting Log." -$string | Out-File -FilePath $logPath - - -. $f1 -. $f2 -. $f3 -. $f4 -. $f5 - -$nssm = Join-Path -Path $userPath -ChildPath '\AppData\Roaming\EmuDeck\backend\wintools\nssm.exe' -$emuName = Get-Content "$savesPath/.emulator" -$lockFile = Join-Path -Path $userPath -ChildPath 'EmuDeck\cloud.lock' -rm -fo -r $lockFile -ErrorAction SilentlyContinue - -# specify the path to the folder you want to watch: - -if ($emuName -eq 'all'){ - $emuPath = "$savesPath" -}elseif($emuName -eq $null -or $emuName -eq ''){ - $emuPath = "$savesPath" - $emuName = 'all' -}else{ - $emuPath = "$savesPath\$emuName" -} - -$Path = "$emuPath" - -# specify which files you want to monitor -$FileFilter = '*' - -# specify whether you want to monitor subfolders as well: -$IncludeSubfolders = $true - -# specify the file or folder properties you want to monitor: -$AttributeFilter = [IO.NotifyFilters]::FileName, [IO.NotifyFilters]::LastWrite - -# Create a dictionary to track the last modified time of each file -$lastModifiedTimes = @{} - -try -{ - $watcher = New-Object -TypeName System.IO.FileSystemWatcher -Property @{ - Path = $Path - Filter = $FileFilter - IncludeSubdirectories = $IncludeSubfolders - NotifyFilter = $AttributeFilter - } - - # define the code that should execute when a change occurs: - $action = { - # the code is receiving this to work with: - - # change type information: - $details = $event.SourceEventArgs - $Name = $details.Name - $FullPath = $details.FullPath - $OldFullPath = $details.OldFullPath - $OldName = $details.OldName - - $blackList = @(".hash", ".last_upload", ".pending_upload", ".watching", "$emuPath") - - # Check if the file is in the blacklist to skip to the next loop - $skip = $blackList | ForEach-Object { $FullPath -like "*$_" } - - if($skip -contains $true){ - Add-Content -Path $logPath -Value "Ignoring blacklisted file" - return - } - - # type of change: - $ChangeType = $details.ChangeType - - # when the change occurred: - $Timestamp = $event.TimeGenerated - - # Check if the file was modified in the last 2 seconds - $lastModifiedTime = $lastModifiedTimes[$FullPath] - if ($lastModifiedTime -and ($Timestamp).Subtract($lastModifiedTime).TotalMilliseconds -lt 500) { - Add-Content -Path $logPath -Value "Ignoring $FullPath because it was modified again too quickly." - return - } - - # Update the last modified time for this file - $lastModifiedTimes[$FullPath] = (Get-Date) - - # save information to a global variable for testing purposes - # so you can examine it later - # MAKE SURE YOU REMOVE THIS IN PRODUCTION! - #$global:all = $details - - # now you can define some action to take based on the - # details about the change event: - - # let's compose a message: - $text = "{0} was {1} at {2}" -f $FullPath, $ChangeType, $Timestamp - Add-Content -Path $logPath -Value "" - Add-Content -Path $logPath -Value $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) { - Add-Content -Path $logPath -Value "No upload" - } else { - Get-Date -Format "yyyy-MM-dd HH:mm:ss" | Out-File -FilePath $savesPath/$emuName/.pending_upload - cloud_sync_uploadEmu -emuName $emuName -mode "$userPath" - - rm -fo -r "$savesPath/$emuName/.pending_upload" -ErrorAction SilentlyContinue - } - } - 'Created' { - if ($skip -contains $true -or $FullPath -eq $savesPath -or $FullPath -eq $emuPath) { - Add-Content -Path $logPath -Value "No upload" - } else { - Get-Date -Format "yyyy-MM-dd HH:mm:ss" | Out-File -FilePath $savesPath/$emuName/.pending_upload - cloud_sync_uploadEmu -emuName $emuName -mode "$userPath" - rm -fo -r "$savesPath/$emuName/.pending_upload" -ErrorAction SilentlyContinue - } - - } - 'Deleted' { "DELETED" - # 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 - Add-Content -Path $logPath -Value "Deletion Handler Start" - Start-Sleep -Seconds 4 - Add-Content -Path $logPath -Value "Deletion Handler End" - } - 'Renamed' { - # this executes only when a file was renamed - $text = "File {0} was renamed to {1}" -f $OldName, $Name - Add-Content -Path $logPath -Value $text - } - - # any unhandled change types surface here: - default { Add-Content -Path $logPath -Value $_ } - } - } - - # subscribe your event handler to all event types that are - # important to you. Do this as a scriptblock so all returned - # event handlers can be easily stored in $handlers: - $handlers = . { - Register-ObjectEvent -InputObject $watcher -EventName Changed -Action $action - Register-ObjectEvent -InputObject $watcher -EventName Created -Action $action - #Register-ObjectEvent -InputObject $watcher -EventName Deleted -Action $action - #Register-ObjectEvent -InputObject $watcher -EventName Renamed -Action $action - } - - # monitoring starts now: - $watcher.EnableRaisingEvents = $true - - Add-Content -Path $logPath -Value "Watching for changes to $Path" - - # since the FileSystemWatcher is no longer blocking PowerShell - # we need a way to pause PowerShell while being responsive to - # incoming events. Use an endless loop to keep PowerShell busy: - do - { - # Wait-Event waits for a second and stays responsive to events - # Start-Sleep in contrast would NOT work and ignore incoming events - Wait-Event -Timeout 1 - - # write a dot to indicate we are still monitoring: - Add-Content -Path $logPath -Value "." -NoNewline - - # Process name to find - $processName = "EmuDeck Launcher" - $cmdFile = Join-Path -Path $savesPath -ChildPath '.watching' - $lockFile = Join-Path -Path $userPath -ChildPath 'EmuDeck\cloud.lock' - - # Check if the process exists - $process = Get-Process | Where-Object { $_.MainWindowTitle -eq $processName } - - - # We exit if it doesn't - if (-not (Test-Path $cmdFile)) { - Add-Content -Path $logPath -Value "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() - Add-Content -Path $logPath -Value "There's no lock file, bye!" - $dialog = steamToast -MessageText "Sync Completed! You can safely turn off your device" - & $nssm stop CloudWatch - $dialog.Close() - exit - } - } - - } while ($true) -} -finally -{ - # this gets executed when the user presses CTRL+C: - - # stop monitoring - $watcher.EnableRaisingEvents = $false - - # remove the event handlers - $handlers | ForEach-Object { - Unregister-Event -SourceIdentifier $_.Name - } - - # event handlers are technically implemented as a special kind - # of background job, so remove the jobs now -}