Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need help with a script #300

Open
Koriebonx98 opened this issue Apr 11, 2024 · 0 comments
Open

need help with a script #300

Koriebonx98 opened this issue Apr 11, 2024 · 0 comments

Comments

@Koriebonx98
Copy link

its not really an issue but just need some help, made a script for playnite, pulls achievements from log and displays with accruement data. since the new update where its a table in the log ive had to rewrite it, but now its not functioing as it was

script is 95% done, need help to get it to write data to json file and after that itll be fine,

Define file paths

$logFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\xenia.log"
$textFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\Achievements{ImageNameNoExt}.txt"
$jsonFile = "{PlayniteDir}\ExtensionsData\cebe6d32-8c46-4459-b993-5a5189d60788\SuccessStory{DatabaseId}.json"
$newJsonFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\Achievements{DatabaseId}.json"

Create text file if it doesn't exist

if (!(Test-Path -Path $textFile)) {
New-Item -Path $textFile -ItemType File
}

Read log file for unlocked achievements

if (Test-Path $logFile) {
$logContent = Get-Content $logFile

# Find unlocked achievements
$unlockedAchievements = $logContent | Select-String -Pattern "Achievement unlocked:" -AllMatches | Select-Object -ExpandProperty Line

# Only proceed if there are unlocked achievements
if ($unlockedAchievements) {
    $unlockedSection = "`n`nUnlocked`n"

    foreach ($achievement in $unlockedAchievements) {
        $achievementName = $achievement -replace "Achievement unlocked:", "" -replace "`r", "" -replace "i> [A-F0-9]{8}", ""
        $achievementName = $achievementName.Trim()
        $unlockedSection += "`n`"" + $achievementName + """ - " + (Get-Date -Format "yyyy-MM-ddTHH:mm:ss")
    }

    # Add the unlocked section to the output
    $output = $unlockedSection
} else {
    $output = "No achievements unlocked."
}

# Save the cleaned content to the text file
$output | Out-File $textFile

# Update JSON file
$jsonContent = Get-Content $newJsonFile | ConvertFrom-Json
$textFileContent = Get-Content $textFile
if ($textFileContent -match "Unlocked") {
    foreach ($achievement in $jsonContent) {
        if ($textFileContent -match ($achievement.Name -replace "^[0-9]+ - ", "")) {
            # Check if the DateUnlocked property exists
            if ($achievement.PSObject.Properties.Name -contains 'DateUnlocked') {
                $achievement.DateUnlocked = (Get-Date -Format "yyyy-MM-ddTHH:mm:ss")
            } else {
                Write-Host "DateUnlocked property does not exist on this object."
            }
        }
    }
    $jsonContent | ConvertTo-Json -Compress | Set-Content $newJsonFile
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant