From 93c2e6e13fa435d8ba171aac5d50b22a6a4b7e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?100=E3=81=AE=E4=BA=BA?= <100@pokemori.jp> Date: Sat, 5 Jun 2021 18:09:36 +0900 Subject: [PATCH] =?UTF-8?q?VirtualCast=E3=81=AE=E3=83=97=E3=83=AD=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E5=AE=9F=E8=A3=85=E3=81=AB=E4=BC=B4?= =?UTF-8?q?=E3=81=86=E4=BB=95=E6=A7=98=E5=A4=89=E6=9B=B4=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ○○○_config というファイルをすべて、プロファイルごとに変換対象とした --- readme.md | 12 +- ...43\202\222\350\265\267\345\213\225.js.cmd" | 215 ++++++++++-------- 2 files changed, 122 insertions(+), 105 deletions(-) diff --git a/readme.md b/readme.md index 21d6fe7..ce1c7d5 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,12 @@ VirtualCast/config.yaml ======================= -`config.yaml` (または `config.yml`) を `config.json` に変換後、VirtualCast.exe を起動する[WSH]スクリプトです。 +`プロファイル名_config.yaml` (または `プロファイル名_config.yml`) を `プロファイル名_config.json` に変換後、VirtualCast.exe を起動する[WSH]スクリプトです。 [WSH]: https://ja.wikipedia.org/wiki/Windows_Script_Host "Windows Script Hostとは、Microsoft Windowsにおいてテキストファイルに記述したスクリプトを実行するスクリプト実行環境である。" 例 --- -`VirtualCast.exe` があるフォルダに次のような `config.yaml` を置いておくと、 +`VirtualCast.exe` があるフォルダに次のような `プロファイル名_config.yaml` を置いておくと、 ```yaml panorama: @@ -30,7 +30,7 @@ cue_card: allow_direct_view: true ``` -次のような `config.json` に変換されます。 +次のような `プロファイル名_config.json` に変換されます。 ```json { @@ -67,10 +67,10 @@ allow_direct_view: true 1. [バーチャルキャストを起動.js.cmd]を好きなフォルダに保存します。 2. `バーチャルキャストを起動.js.cmd` をダブルクリックして実行します。 -3. `config.json` の内容をもとに `config.yaml` が作成された後、バーチャルキャストが起動します。 -4. `config.yaml` が存在する場合、変換して `config.json` に上書き保存され、その後バーチャルキャストが起動します。 +3. `default_config.json` の内容をもとに `default_config.yaml` が作成された後、バーチャルキャストが起動します。 +4. `default_config.yaml` が存在する場合、変換して `default_config.json` に上書き保存され、その後バーチャルキャストが起動します。 5. `VirtualCast.exe` を直接起動する代わりに、常に `バーチャルキャストを起動.js.cmd` からバーチャルキャストを起動するようにしておくと、 - `config.json` の更新を意識せずにすむため便利です。 + `default_config.json` の更新を意識せずにすむため便利です。 [バーチャルキャストを起動.js.cmd]: https://esperecyan.github.io/virtualcast-config/%E3%83%90%E3%83%BC%E3%83%81%E3%83%A3%E3%83%AB%E3%82%AD%E3%83%A3%E3%82%B9%E3%83%88%E3%82%92%E8%B5%B7%E5%8B%95.js.cmd diff --git "a/\343\203\220\343\203\274\343\203\201\343\203\243\343\203\253\343\202\255\343\203\243\343\202\271\343\203\210\343\202\222\350\265\267\345\213\225.js.cmd" "b/\343\203\220\343\203\274\343\203\201\343\203\243\343\203\253\343\202\255\343\203\243\343\202\271\343\203\210\343\202\222\350\265\267\345\213\225.js.cmd" index ebf0be8..7e53151 100644 --- "a/\343\203\220\343\203\274\343\203\201\343\203\243\343\203\253\343\202\255\343\203\243\343\202\271\343\203\210\343\202\222\350\265\267\345\213\225.js.cmd" +++ "b/\343\203\220\343\203\274\343\203\201\343\203\243\343\203\253\343\202\255\343\203\243\343\202\271\343\203\210\343\202\222\350\265\267\345\213\225.js.cmd" @@ -5,7 +5,7 @@ REM JScript9.dll EXIT %errorlevel% */ /** - * @file uconfig.yamlv(܂ config.yml) uconfig.jsonvɕϊAVirtualCast.exe N܂B + * @file uvt@C_config.yamlv(܂ vt@C_config.yml) uvt@C_config.jsonvɕϊAVirtualCast.exe N܂B * @version 2.0.0 * @license MPL-2.0 * @author 100̐l @@ -26,18 +26,6 @@ var EXE_URL = 'steam://rungameid/947890'; */ var CONFIG_FOLDER_PATH = Shell.ExpandEnvironmentStrings('%USERPROFILE%\\Documents\\My Games\\VirtualCast'); -/** - * o͐t@CpXB - * @constant {string} - */ -var OUTPUT_FILE_NAME = 'config.json'; - -/** - * ͌t@CBo͐t@CƂɍ쐬ꍇ́Aŏ̃t@CgpB - * @constant {string} - */ -var INPUT_FILE_NAMES = ['config.yaml', 'config.yml']; - /** * [UTF-8 | Encoding Standard \ @ Wi{j]{@link https://triple-underscore.github.io/Encoding-ja.html#utf-8-decode} * @constant {number} @@ -143,127 +131,142 @@ function isValidConfig(config, filename) var folder = FileSystemObject.GetFolder(CONFIG_FOLDER_PATH); -var outputFile, inputFile; +var profileNameFilesPairs = { }; var files = new Enumerator(folder.files); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); - if (file.Name === OUTPUT_FILE_NAME) { - outputFile = file; - } else if (INPUT_FILE_NAMES.includes(file.Name)) { - if (inputFile) { + var result = /(.+)_config\.(json|yaml|yml)$/.exec(file.Name); + if (!result) { + continue; + } + var profileName = result[1]; + var extension = result[2]; + + if (!(profileName in profileNameFilesPairs)) { + profileNameFilesPairs[profileName] = { }; + } + + if (extension === 'json') { + profileNameFilesPairs[profileName].output = file; + } else { + if (profileNameFilesPairs[profileName].input) { + // t@Cu.yamlvu.ymlv̈ႢȂt@C Shell.Popup( - 'u' + inputFile.Name + 'vu' + file.Name + 'v݂̂Ă܂Bǂ炩‚łKv܂B', + 'u' + profileName + '_config.yamlvu' + profileName + '_config.ymlv݂̂Ă܂Bǂ炩‚łKv܂B', 0, WSH.ScriptName, vbOKOnly + vbCritical ); return; - } else { - inputFile = file; } + profileNameFilesPairs[profileName].input = file; } } -if (inputFile) { - // config.yaml config.json - if ((outputFile || folder).Attributes & ReadOnly) { - Shell.Popup( - outputFile - ? 'u' + outputFile.Name + 'v㏑錠܂B' - : 'u' + folder.Name + 'vtH_Ƀt@C쐬錠Ȃ߁Au' + OUTPUT_FILE_NAME + 'v쐬ł܂B', - 0, - WSH.ScriptName, - vbOKOnly + vbCritical - ); - return; - } +if (Object.keys(profileNameFilesPairs).length === 0) { + Shell.Popup(CONFIG_FOLDER_PATH + ' ɁAu_configv܂ރt@C͌‚܂B', 0, WSH.ScriptName, vbOKOnly + vbCritical); + return; +} - var yaml = getFileContents(inputFile.Path); - - var configs; - try { - configs = jsyaml.safeLoadAll(yaml, null, {filename: inputFile.Path}); - } catch (exception) { - if (exception.name === 'YAMLException') { - var errorMessage = 'u' + inputFile.Name + 'v͉Ă܂Bȉ̃G[܂B'; - if (outputFile) { - errorMessage += 'u' + inputFile.Name + 'v폜A܂͖O̕ύXs΁A' - + 'NɁu' + outputFile.name + 'v̓eƂɁu' + INPUT_FILE_NAMES[0] + 'v쐬܂B'; - } +for (var profileName in profileNameFilesPairs) { + var files = profileNameFilesPairs[profileName]; + if (files.input) { + // config.yaml config.json + var outputFileName = profileName + '_config.json'; + if ((files.output || folder).Attributes & ReadOnly) { Shell.Popup( - errorMessage + '\n\n' + exception.name + ': ' + exception.message, + files.output + ? 'u' + files.output.Name + 'v㏑錠܂B' + : 'u' + folder.Name + 'vtH_Ƀt@C쐬錠Ȃ߁Au' + outputFileName + 'v쐬ł܂B', 0, WSH.ScriptName, vbOKOnly + vbCritical ); return; - } else { - throw exception; } - } - var config = configs[0]; - var argument = getArgument('--esperecyan-document-index'); - if (argument) { - var index = Number.parseInt(argument); - if (configs.length <= index) { + var yaml = getFileContents(files.input); + + var configs; + try { + configs = jsyaml.safeLoadAll(yaml, null, {filename: files.input.Path}); + } catch (exception) { + if (exception.name === 'YAMLException') { + var errorMessage = 'u' + files.input.Name + 'v͉Ă܂Bȉ̃G[܂B'; + if (files.output) { + errorMessage += 'u' + files.input.Name + 'v폜A܂͖O̕ύXs΁A' + + 'NɁu' + files.output.Name + 'v̓eƂɁu' + profileName + '_config.yamlv쐬܂B'; + } + Shell.Popup( + errorMessage + '\n\n' + exception.name + ': ' + exception.message, + 0, + WSH.ScriptName, + vbOKOnly + vbCritical + ); + return; + } else { + throw exception; + } + } + + var config = configs[0]; + var argument = getArgument('--esperecyan-document-index'); + if (argument) { + var index = Number.parseInt(argument); + if (configs.length <= index) { + Shell.Popup( + files.input.Name + 'ɂ' + configs.length + '‚YAMLhLg܂܂Ă̂ŁA' + + '--esperecyan-document-index ɂ0`' + (configs.length - 1) + 'w肷Kv܂B', + 0, + WSH.ScriptName, + vbOKOnly + vbCritical + ); + return; + } + config = configs[index]; + } + + if (!isValidConfig(config, files.input.Name)) { + return; + } + + putFileContents(folder.Path + '\\' + profileName + '_config.json', JSON.stringify(config, null, '\t').replace(/\n/g, '\r\n')); + } else { + // config.json config.yaml + if (folder.Attributes & ReadOnly) { Shell.Popup( - inputFile.Name + 'ɂ' + configs.length + '‚YAMLhLg܂܂Ă̂ŁA' - + '--esperecyan-document-index ɂ0`' + (configs.length - 1) + 'w肷Kv܂B', + 'u' + folder.Name + 'vtH_Ƀt@C쐬錠Ȃ߁Au' + profileName + '_config.yamlv쐬ł܂B', 0, WSH.ScriptName, vbOKOnly + vbCritical ); return; } - config = configs[index]; - } - if (!isValidConfig(config, inputFile.Name)) { - return; - } + var json = getFileContents(files.output.Path); - putFileContents(folder.Path + '\\' + OUTPUT_FILE_NAME, JSON.stringify(config, null, '\t').replace(/\n/g, '\r\n')); -} else if (outputFile) { - // config.json config.yaml - if (folder.Attributes & ReadOnly) { - Shell.Popup( - 'u' + folder.Name + 'vtH_Ƀt@C쐬錠Ȃ߁Au' + INPUT_FILE_NAMES[0] + 'v쐬ł܂B', - 0, - WSH.ScriptName, - vbOKOnly + vbCritical - ); - return; - } + var configJSON; + try { + configJSON = JSON.parse(json); + } catch (exception) { + Shell.Popup( + 'u' + files.output.Name + 'v͉Ă܂Bȉ̃G[܂B\n\n' + exception.name + ': ' + exception.message, + 0, + WSH.ScriptName, + vbOKOnly + vbCritical + ); + return; + } - var json = getFileContents(outputFile.Path); + if (!isValidConfig(configJSON, files.output.Name)) { + return; + } - var configJSON; - try { - configJSON = JSON.parse(json); - } catch (exception) { - Shell.Popup( - 'u' + outputFile.Name + 'v͉Ă܂Bȉ̃G[܂B\n\n' + exception.name + ': ' + exception.message, - 0, - WSH.ScriptName, - vbOKOnly + vbCritical + putFileContents( + profileName + '_config.yaml', + jsyaml.safeDump(configJSON, {indent: 4, lineWidth: -1}).replace(/\n/g, '\r\n') ); - return; - } - - if (!isValidConfig(configJSON, outputFile.Name)) { - return; } - - putFileContents( - INPUT_FILE_NAMES[0], - jsyaml.safeDump(configJSON, {indent: 4, lineWidth: -1}).replace(/\n/g, '\r\n') - ); -} else { - Shell.Popup([OUTPUT_FILE_NAME].concat(INPUT_FILE_NAMES).map(function (name) { - return 'u' + name + 'v'; - }) + '̂‚܂B', 0, WSH.ScriptName, vbOKOnly + vbCritical); - return; } Shell.Run('explorer ' + EXE_URL); @@ -3020,6 +3023,20 @@ if (!String.prototype.startsWith) { }; } +/** + * @see [String.prototype.endsWith() - JavaScript | MDN]{@link + * https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith#Polyfill} + * @license CC0-1.0 AND MIT (ł邩sA炭CC0-1.0) + */ + if (!String.prototype.endsWith) { + String.prototype.endsWith = function(search, this_len) { + if (this_len === undefined || this_len > this.length) { + this_len = this.length; + } + return this.substring(this_len - search.length, this_len) === search; + }; + } + if (!Number.parseInt) { Number.parseInt = parseInt; }