Skip to content

Commit

Permalink
cloudwatcher log
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoonDorise committed Jul 5, 2024
1 parent 6368c80 commit 2fcf0ad
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions tools/cloudSync/cloud_sync_watcher.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}

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

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

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

0 comments on commit 2fcf0ad

Please sign in to comment.