diff --git a/readme.md b/readme.md index e2e1c51..14dcea9 100644 --- a/readme.md +++ b/readme.md @@ -89,6 +89,59 @@ allow_direct_view: true 起動オプション -------------- +### `--esperecyan-document-index=[数字]` (0から始まる整数) +一つのファイル内に複数のYAMLドキュメントが埋め込まれていた場合、読み込むドキュメントを切り替えます。 + +例: + +```yaml +--- +niconico: + character_models: + - 32797 + - 32806 + - 32813 +--- # コメント +niconico: + character_models: + - 40000 + - 40001 + - 40023 +--- +niconico: + character_models: + - 41036 +``` + +#### `--esperecyan-document-index==0` の場合 +指定しなかった場合と同じ。 + +```json +{ + "niconico": { + "character_models": [ + 32797, + 32806, + 32813 + ] + } +} +``` + +#### `--esperecyan-document-index==1` の場合 + +```json +{ + "niconico": { + "character_models": [ + 40000, + 40001, + 40023 + ] + } +} +``` + ### `--esperecyan-niconico-character-models-offset-16x=[数字]` `niconico.character_models` の順番をズラします。 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 c412084..0cfadec 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" @@ -113,6 +113,21 @@ function putFileContents(path, contents) stream.Close(); } +/** + * w肳ꂽR}hC̒l擾܂B + * @param {string} name + * @returns {string} + */ +function getArgument(name) +{ + for (var i = 0, l = WSH.Arguments.length; i < l; i++) { + if (WSH.Arguments(i).startsWith(name + '=')) { + return WSH.Arguments(i).replace(name + '=', ''); + } + } + return ''; +} + /** * w肳ꂽl Object łȂ΁AG[bZ[W\܂B * @param {*} config @@ -184,9 +199,9 @@ if (inputFile) { var yaml = getFileContents(inputFile.Path); - var config; + var configs; try { - config = jsyaml.safeLoad(yaml, {filename: inputFile.Path}); + configs = jsyaml.safeLoadAll(yaml, null, {filename: inputFile.Path}); } catch (exception) { if (exception.name === 'YAMLException') { var errorMessage = 'u' + inputFile.Name + 'v͉Ă܂Bȉ̃G[܂B'; @@ -206,22 +221,35 @@ if (inputFile) { } } + var config = configs[0]; + var argument = getArgument('--esperecyan-document-index'); + if (argument) { + var index = Number.parseInt(argument); + if (configs.length <= index) { + Shell.Popup( + inputFile.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, inputFile.Name)) { return; } if (typeof config.niconico === 'object' && config.niconico !== null && Array.isArray(config.niconico.character_models)) { - for (var i = 0, l = WSH.Arguments.length; i < l; i++) { - if (WSH.Arguments(i).startsWith('--esperecyan-niconico-character-models-offset-16x=')) { - var offset = Number.parseInt( - WSH.Arguments(i).replace('--esperecyan-niconico-character-models-offset-16x=', '') - ) * MAX_NICONICO_CHARCTER_MODELS_COUNT; - if (config.niconico.character_models.length > offset) { - config.niconico.character_models - = config.niconico.character_models.concat(config.niconico.character_models.splice(0, offset)); - } - break; + var argument = getArgument('--esperecyan-niconico-character-models-offset-16x'); + if (argument) { + var offset = Number.parseInt(argument) * MAX_NICONICO_CHARCTER_MODELS_COUNT; + if (config.niconico.character_models.length > offset) { + config.niconico.character_models + = config.niconico.character_models.concat(config.niconico.character_models.splice(0, offset)); } } }