From 2fcf0adebe20bdbad3ebcd2261af90ba28a091da Mon Sep 17 00:00:00 2001 From: Dragoon Dorise Date: Fri, 5 Jul 2024 22:54:10 +0200 Subject: [PATCH] cloudwatcher log --- tools/cloudSync/cloud_sync_watcher.ps1 | 34 ++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/cloudSync/cloud_sync_watcher.ps1 b/tools/cloudSync/cloud_sync_watcher.ps1 index 45f5beac..9139829c 100644 --- a/tools/cloudSync/cloud_sync_watcher.ps1 +++ b/tools/cloudSync/cloud_sync_watcher.ps1 @@ -1,12 +1,16 @@ $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 @@ -69,7 +73,7 @@ try $skip = $blackList | ForEach-Object { $FullPath -like "*$_" } if($skip -contains $true){ - Write-Host "Ignoring blacklisted file" + Add-Content -Path $logPath -Value "Ignoring blacklisted file" return } @@ -82,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) { - Write-Host "Ignoring $FullPath because it was modified again too quickly." + Add-Content -Path $logPath -Value "Ignoring $FullPath because it was modified again too quickly." return } @@ -99,8 +103,8 @@ try # let's compose a message: $text = "{0} was {1} at {2}" -f $FullPath, $ChangeType, $Timestamp - Write-Host "" - Write-Host $text -ForegroundColor DarkYellow + 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) @@ -108,7 +112,7 @@ try 'Changed' { if ($skip -contains $true -or $FullPath -eq $savesPath -or $FullPath -eq $emuPath) { - Write-Host "No upload" + 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" @@ -118,7 +122,7 @@ try } 'Created' { if ($skip -contains $true -or $FullPath -eq $savesPath -or $FullPath -eq $emuPath) { - Write-Host "No upload" + 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" @@ -130,18 +134,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 - Write-Host "Deletion Handler Start" -ForegroundColor Gray + Add-Content -Path $logPath -Value "Deletion Handler Start" Start-Sleep -Seconds 4 - Write-Host "Deletion Handler End" -ForegroundColor Gray + 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 - Write-Host $text -ForegroundColor Yellow + Add-Content -Path $logPath -Value $text } # any unhandled change types surface here: - default { Write-Host $_ -ForegroundColor Red -BackgroundColor White } + default { Add-Content -Path $logPath -Value $_ } } } @@ -158,7 +162,7 @@ try # monitoring starts now: $watcher.EnableRaisingEvents = $true - Write-Host "Watching for changes to $Path" + 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 @@ -170,7 +174,7 @@ try Wait-Event -Timeout 1 # write a dot to indicate we are still monitoring: - Write-Host "." -NoNewline + Add-Content -Path $logPath -Value "." -NoNewline # Process name to find $processName = "EmuDeck Launcher" @@ -183,13 +187,13 @@ try # We exit if it doesn't if (-not (Test-Path $cmdFile)) { - Write-Host "There's no .watching file" + 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() - Write-Host "There's no lock file, bye!" + 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()