From 5c59a700b0902bef8dccf0272156930db6d00ea6 Mon Sep 17 00:00:00 2001 From: Valianton Date: Wed, 27 Dec 2023 17:55:16 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= =?UTF-8?q?=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D1=89=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- updater/newUpdater/rus.ps1 | 329 +++++++++++++++++++++---------------- 1 file changed, 185 insertions(+), 144 deletions(-) diff --git a/updater/newUpdater/rus.ps1 b/updater/newUpdater/rus.ps1 index 0416d1b..5c4534c 100644 --- a/updater/newUpdater/rus.ps1 +++ b/updater/newUpdater/rus.ps1 @@ -1,88 +1,99 @@ Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -function Get-IniFile { - param( - [parameter(Mandatory = $true)] [string] $filePath - ) - +function Get-IniFile +{ + param( + [parameter(Mandatory = $true)] [string] $filePath + ) + $anonymous = "NoSection" - - $ini = @{} - switch -regex -file $filePath - { + + $ini = @{ } + switch -regex -file $filePath + { "^\[(.+)\]$" # Section - { - $section = $matches[1] - $ini[$section] = @{} - $CommentCount = 0 - } + { + $section = $matches[1] + $ini[$section] = @{ } + $CommentCount = 0 + } "^(;.*)$" # Comment - { - if (!($section)) - { - $section = $anonymous - $ini[$section] = @{} - } - $value = $matches[1] - $CommentCount = $CommentCount + 1 - $name = "Comment" + $CommentCount - $ini[$section][$name] = $value - } + { + if (!($section)) + { + $section = $anonymous + $ini[$section] = @{ } + } + $value = $matches[1] + $CommentCount = $CommentCount + 1 + $name = "Comment" + $CommentCount + $ini[$section][$name] = $value + } "(.+?)\s*=\s*(.*)" # Key - { - if (!($section)) - { - $section = $anonymous - $ini[$section] = @{} - } - $name,$value = $matches[1..2] - $ini[$section][$name] = $value - } - } - return $ini + { + if (!($section)) + { + $section = $anonymous + $ini[$section] = @{ } + } + $name, $value = $matches[1..2] + $ini[$section][$name] = $value + } + } + return $ini } -Function Get-GameFolder() { - return (Get-ItemProperty -Path $HKCU_SOFTWARE_ANKAMA\$wakfuKey).GameFolder +Function Get-GameFolder() +{ + return (Get-ItemProperty -Path $HKCU_SOFTWARE_ANKAMA\$wakfuKey).GameFolder } -Function Get-Version() { - return (Get-ItemProperty -Path $HKCU_SOFTWARE_ANKAMA\$wakfuKey).version +Function Get-Version() +{ + return (Get-ItemProperty -Path $HKCU_SOFTWARE_ANKAMA\$wakfuKey).version } -Function New-RegKey($name, $value) { - New-ItemProperty -Path $HKCU_SOFTWARE_ANKAMA\$wakfuKey -Name $name -Value $value -PropertyType "String" +Function New-RegKey($name, $value) +{ + New-ItemProperty -Path $HKCU_SOFTWARE_ANKAMA\$wakfuKey -Name $name -Value $value -PropertyType "String" } -Function Update-RegKey($name, $value) { - Set-ItemProperty -Path $HKCU_SOFTWARE_ANKAMA\$wakfuKey -Name $name -Value $value +Function Update-RegKey($name, $value) +{ + Set-ItemProperty -Path $HKCU_SOFTWARE_ANKAMA\$wakfuKey -Name $name -Value $value } -Function Checkpoint-ValidPath($path) { - $v = ".release.infos.json" - return [System.IO.File]::Exists("$path\$v") +Function Checkpoint-ValidPath($path) +{ + $v = ".release.infos.json" + return [System.IO.File]::Exists("$path\$v") } -Function Get-Folder($initialDirectory) { +Function Get-Folder($initialDirectory) +{ [void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') $FolderBrowserDialog = New-Object System.Windows.Forms.FolderBrowserDialog $FolderBrowserDialog.RootFolder = 'MyComputer' - if ($initialDirectory) { $FolderBrowserDialog.SelectedPath = $initialDirectory } + if ($initialDirectory) + { + $FolderBrowserDialog.SelectedPath = $initialDirectory + } - if($FolderBrowserDialog.ShowDialog() -eq "OK") + if ($FolderBrowserDialog.ShowDialog() -eq "OK") { $folder += $FolderBrowserDialog.SelectedPath } return $folder } -Function CreateDistrib() { - New-Item –Path $HKCU_SOFTWARE_ANKAMA –Name $wakfuKey - (New-RegKey 'GameFolder' '') - (New-RegKey 'version' 0) - Write-Output "Создан новый дистрибутив для русификатора" +Function CreateDistrib() +{ + New-Item –Path $HKCU_SOFTWARE_ANKAMA –Name $wakfuKey + (New-RegKey 'GameFolder' '') + (New-RegKey 'version' 0) + Write-Output "Создан новый дистрибутив для русификатора" } #app @@ -104,23 +115,29 @@ $HKCU_SOFTWARE = "HKCU:\SOFTWARE" $HKCU_SOFTWARE_ANKAMA = "$HKCU_SOFTWARE\$ankamaKey" Write-Output "Поиск ключа в реестре" -if (!(Get-Item -Path $HKCU_SOFTWARE_ANKAMA -ErrorAction SilentlyContinue)) { - Write-Output "Создание ключа реестра" - New-Item –Path $HKCU_SOFTWARE –Name $ankamaKey - Write-Output "Запуск CreateDistrib" - (CreateDistrib) - $version = "0" -} else { - Write-Output "Ключ реестра найден" - $WakfuRegObject = (Get-ChildItem $HKCU_SOFTWARE_ANKAMA -Include $wakfuKey -Recurse) - Write-Output "WakfuRegObject: $WakfuRegObject" - if (!$WakfuRegObject) { - Write-Output "Запуск CreateDistrib" - (CreateDistrib) - } else { - $version = (Get-Version) - Write-Output "Текущая версия русификатора: $version" - } +if (!(Get-Item -Path $HKCU_SOFTWARE_ANKAMA -ErrorAction SilentlyContinue)) +{ + Write-Output "Создание ключа реестра" + New-Item –Path $HKCU_SOFTWARE –Name $ankamaKey + Write-Output "Запуск CreateDistrib" + (CreateDistrib) + $version = "0" +} +else +{ + Write-Output "Ключ реестра найден" + $WakfuRegObject = (Get-ChildItem $HKCU_SOFTWARE_ANKAMA -Include $wakfuKey -Recurse) + Write-Output "WakfuRegObject: $WakfuRegObject" + if (!$WakfuRegObject) + { + Write-Output "Запуск CreateDistrib" + (CreateDistrib) + } + else + { + $version = (Get-Version) + Write-Output "Текущая версия русификатора: $version" + } } Write-Output "Создание GUI формы" @@ -129,13 +146,13 @@ Add-Type -assembly System.Windows.Forms #Label Write-Output "Создание подписей-1" $FormLabel = New-Object System.Windows.Forms.Label -$FormLabel.Location = New-Object System.Drawing.Point(20,10) +$FormLabel.Location = New-Object System.Drawing.Point(20, 10) $FormLabel.Text = "Путь до игры" $FormLabel.AutoSize = $true Write-Output "Создание подписей-2" $InfoLabel = New-Object System.Windows.Forms.Label -$InfoLabel.Location = New-Object System.Drawing.Point(20,100) +$InfoLabel.Location = New-Object System.Drawing.Point(20, 100) $InfoLabel.ForeColor = [System.Drawing.ColorTranslator]::FromHtml("#00A2E8") $InfoLabel.AutoSize = $true @@ -143,21 +160,24 @@ Write-Output "Создание подписей-3" $FolderText = New-Object system.Windows.Forms.TextBox $FolderText.multiline = $false $FolderText.width = 435 -$FolderText.location = New-Object System.Drawing.Point(25,40) +$FolderText.location = New-Object System.Drawing.Point(25, 40) $FolderText.Add_TextChanged({ - if ((Checkpoint-ValidPath $FolderText.text)) { - $InstallButton.enabled = $true - (Update-RegKey 'GameFolder' $FolderText.text) - } else { - $InstallButton.enabled = $false - } + if ((Checkpoint-ValidPath $FolderText.text)) + { + $InstallButton.enabled = $true + (Update-RegKey 'GameFolder' $FolderText.text) + } + else + { + $InstallButton.enabled = $false + } }) # FolderButton Write-Output "Создание контрола выбора пути" $FolderButton = New-Object System.Windows.Forms.Button -$FolderButton.Location = New-Object System.Drawing.Size(360,10) -$FolderButton.Size = New-Object System.Drawing.Size(100,20) +$FolderButton.Location = New-Object System.Drawing.Size(360, 10) +$FolderButton.Size = New-Object System.Drawing.Size(100, 20) $FolderButton.Text = "Выбрать папку" # Install Button @@ -166,62 +186,79 @@ $installButtonWidth = 200 $InstallButton_positionX = $appWidth / 2 - $installButtonWidth / 2 $InstallButton = New-Object System.Windows.Forms.Button $InstallButton.Location = New-Object System.Drawing.Size($InstallButton_positionX, 70) -$InstallButton.Size = New-Object System.Drawing.Size($installButtonWidth,20) +$InstallButton.Size = New-Object System.Drawing.Size($installButtonWidth, 20) $InstallButton.enabled = $false $InstallButton.Add_Click({ - $targetPath = $FolderText.text - $modPath = "$targetPath\mods" - # update carcas - Write-Output "Обновление ресурса" - Remove-Item $modPath -Force -Recurse -ErrorAction SilentlyContinue - New-Item -ItemType directory -Path $modPath - - # alias - curl - Write-Output "Получение пакета архиватора" - Invoke-WebRequest https://github.com/Valianton/Wakfu-Translate/raw/master/Instruments/zip.exe -OutFile $modPath\zip.exe - Write-Output "Получение пакета ресурса" - Invoke-WebRequest https://github.com/Valianton/Wakfu-Translate/raw/master/data/data.zip -OutFile $modPath\data.zip - Write-Output "Разархивирование ресурса" - Expand-Archive -LiteralPath $modPath\data.zip -DestinationPath $modPath - - # update russifier - Write-Output "Обновление русификатора" - $zip = "$targetPath\mods\zip.exe" - Set-Location -Path $modPath - $sourceLang = "$targetPath\contents\i18n\i18n_en.jar" - Invoke-Expression "$zip $sourceLang texts_en.properties" - $sourceFont = "$targetPath\contents\gui_jar\gui.jar" - Invoke-Expression "$zip -r $sourceFont theme" - Write-Output "Обновление ключа реестра" - (Update-RegKey 'version' $NewVersion) - Write-Output "Обновление заголовков формы" - $window_form.Text = "ВАКФУ Русификатор v$NewVersion" - $InfoLabel.Text = "Русификатор успешно установлен" + $path = $FolderText.text; + $targetPath = $path.Replace(' ', '` ') + $modPath = "$path\mods" + # update carcas + Write-Host "Обновление ресурса" + Remove-Item $modPath -Force -Recurse -ErrorAction SilentlyContinue + New-Item -ItemType directory -Path $modPath + + # alias - curl + Write-Host "Получение пакета архиватора" + Invoke-WebRequest https://github.com/Valianton/Wakfu-Translate/raw/master/Instruments/zip.exe -OutFile $modPath\zip.exe + Write-Host "Получение пакета ресурса" + Invoke-WebRequest https://github.com/Valianton/Wakfu-Translate/raw/master/data/data.zip -OutFile $modPath\data.zip + Write-Host "Разархивирование ресурса" + Expand-Archive -LiteralPath $modPath\data.zip -DestinationPath $modPath + + # update russifier + Write-Host "Обновление русификатора" + $zip = "$targetPath\mods\zip.exe" + Set-Location -Path $modPath + $sourceLang = "$targetPath\contents\i18n\i18n_en.jar" + try + { + Invoke-Expression "$zip $sourceLang texts_en.properties" + } + catch + { + Write-Host "Произошла ошибка: $_" + return + } + $sourceFont = "$targetPath\contents\gui_jar\gui.jar" + Invoke-Expression "$zip -r $sourceFont theme" + Write-Host "Обновление ключа реестра" + (Update-RegKey 'version' $NewVersion) + Write-Host "Обновление заголовков формы" + $window_form.Text = "ВАКФУ Русификатор v$NewVersion" + $InfoLabel.Text = "Русификатор успешно установлен" + Write-Host "Русификатор успешно обновлен до версии $NewVersion" }) $FolderButton.Add_Click({ - $defaultFolder = (Get-GameFolder) - - if (!$defaultFolder) { - $defaultFolder = 'C:\Users' - } - - ($selectedFolder = Get-Folder $defaultFolder) - $FolderText.text = $selectedFolder - if ($selectedFolder) { - if (!(Checkpoint-ValidPath $selectedFolder)) { - if ($FolderText.text) { - if ((Checkpoint-ValidPath $FolderText.text)) { - $InstallButton.enabled = $true - } - } - } else { - Write-Warning $selectedFolder - (Update-RegKey 'GameFolder' $selectedFolder) - $FolderText.text = $selectedFolder - } - } + $defaultFolder = (Get-GameFolder) + + if (!$defaultFolder) + { + $defaultFolder = 'C:\Users' + } + + ($selectedFolder = Get-Folder $defaultFolder) + $FolderText.text = $selectedFolder + if ($selectedFolder) + { + if (!(Checkpoint-ValidPath $selectedFolder)) + { + if ($FolderText.text) + { + if ((Checkpoint-ValidPath $FolderText.text)) + { + $InstallButton.enabled = $true + } + } + } + else + { + Write-Warning $selectedFolder + (Update-RegKey 'GameFolder' $selectedFolder) + $FolderText.text = $selectedFolder + } + } }) @@ -230,16 +267,20 @@ $formTitle = "ВАКФУ Русификатор" $installText = "Установить Русификатор" Write-Output "Обновление данных о русификаторе" -if ($version) { - if ($NewVersion -gt $version) { - $formTitle = "ВАКФУ Русификатор v$version (доступна версия $NewVersion)" - $installText = "Обновить Русификатор" - $InfoLabel.Text = "В наличии имеется новая версия русификатора" - } else { - $formTitle = "ВАКФУ Русификатор v$version" - $installText = "Переустановить Русификатор" - $InfoLabel.Text = "Русификатор обновлен до последней версии, но его можно переустановить" - } +if ($version) +{ + if ($NewVersion -gt $version) + { + $formTitle = "ВАКФУ Русификатор v$version (доступна версия $NewVersion)" + $installText = "Обновить Русификатор" + $InfoLabel.Text = "В наличии имеется новая версия русификатора" + } + else + { + $formTitle = "ВАКФУ Русификатор v$version" + $installText = "Переустановить Русификатор" + $InfoLabel.Text = "Русификатор обновлен до последней версии, но его можно переустановить" + } } $InstallButton.Text = $installText @@ -257,4 +298,4 @@ $window_form.Controls.Add($InfoLabel) $FolderText.text = (Get-GameFolder) Write-Output "Отображение формы" -$window_form.ShowDialog() +$window_form.ShowDialog() \ No newline at end of file