public void IsNotScenarioTest2(string path) { var fullName = Path.GetFullPath(Path.Combine(TestDirPath, path)); Assert.True(File.Exists(fullName) || Directory.Exists(fullName)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName)); }
public void IsScenarioTest(string path, ScenarioParameterType scenarioParameterType, ContainerParameterType containerParameterType) { var fullName = Path.GetFullPath(Path.Combine(TestDirPath, "正常系/", path)); Assert.True(CardWirthScenario.IsScenarioSummary(fullName, scenarioParameterType, containerParameterType)); Assert.True(CardWirthScenario.IsScenarioSummary(fullName)); Assert.True(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Any, ContainerParameterType.Any)); }
public void TestScenarioNotFoundException(string filename) { var fullName = Path.GetFullPath(Path.Combine(TestDirPath, "異常系/", filename)); var ex = Assert.Throws <ScenarioNotFoundException>(() => { CardWirthScenario.GetScenarioSummary(fullName); }); }
public void TestPasswordedZipFailed(string filename) { var fullName = Path.GetFullPath(Path.Combine(TestDirPath, "異常系/InvalidScenarioException/PasswordedZip/", filename)); var ex = Assert.Throws <InvalidScenarioException>(() => { CardWirthScenario.GetScenarioSummary(fullName); }); }
public void TestUnsupportedContainerTypeException(string filename) { var fullName = Path.GetFullPath(Path.Combine(TestDirPath, "異常系/UnsupportedContainerTypeException/", filename)); var ex = Assert.Throws <UnsupportedContainerTypeException>(() => { CardWirthScenario.GetScenarioSummary(fullName); }); }
public void IsWsnScenarioTest(string path) { var fullName = Path.GetFullPath(Path.Combine(TestDirPath, "正常系/", path)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Classic, ContainerParameterType.Any)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Next, ContainerParameterType.Any)); Assert.True(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Wsn, ContainerParameterType.Any)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Classic)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Next)); Assert.True(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Wsn)); }
public void IsDirectoryScenarioTest(string path) { var fullName = Path.GetFullPath(Path.Combine(TestDirPath, "正常系/", path)); Assert.True(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Any, ContainerParameterType.Directory)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Any, ContainerParameterType.ZipFile)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Any, ContainerParameterType.CabFile)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ScenarioParameterType.Any, ContainerParameterType.WsnFile)); Assert.True(CardWirthScenario.IsScenarioSummary(fullName, ContainerParameterType.Directory)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ContainerParameterType.CabFile)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ContainerParameterType.ZipFile)); Assert.False(CardWirthScenario.IsScenarioSummary(fullName, ContainerParameterType.WsnFile)); }
public void TestClassic(string filename, ContainerType containerType) { var fullName = Path.GetFullPath(Path.Combine(TestDirPath, "正常系/", filename)); var scenarioSummary = CardWirthScenario.GetScenarioSummary(fullName); Assert.Equal(ScenarioType.Classic, scenarioSummary.ScenarioType); Assert.Equal("ゴブリンの洞窟", scenarioSummary.Name); Assert.Equal(1, scenarioSummary.LevelMin); Assert.Equal(3, scenarioSummary.LevelMax); Assert.Equal("齋藤 洋", scenarioSummary.Author); Assert.Equal(" 町外れの洞窟にゴブリンと思しき妖魔が\r\n住み着いた。夜間に洞窟から抜け出しては\r\n近隣の畑や民家を荒らし、旅人を襲って荷\r\n物を奪うなど、大きな被害が出ている。\r\n\r\n 近隣に住む農民達は共同で金を出し合い\r\n冒険者を雇ってゴブリン退治を依頼するこ\r\nとを決定した…\r\n", scenarioSummary.Description); Assert.Equal(containerType, scenarioSummary.ContainerType); Assert.Equal(File.GetLastWriteTime(fullName), scenarioSummary.LastWriteTime); Assert.Equal(fullName, scenarioSummary.FullName); Assert.IsType <SummaryWsm>(scenarioSummary.SummaryInfo); }
protected override void ProcessRecord() { WriteVerbose("Path:" + String.Join(",", Path)); WriteVerbose("LiteralPath:" + String.Join(",", LiteralPath)); WriteVerbose("_paths:" + String.Join(",", _paths)); WriteVerbose("_suppressWildcardExpansion:" + _suppressWildcardExpansion.ToString()); WriteVerbose("ScenarioType:" + ScenarioType.ToString()); WriteVerbose("ContaierType:" + ContainerType.ToString()); foreach (string path in _paths) { WriteVerbose("path:" + path); if (!InvokeProvider.Item.Exists(path, true, _suppressWildcardExpansion)) { WriteObject(false); continue; } var items = Enumerable.Empty <PSObject>(); try { items = InvokeProvider.Item.Get(new string[] { path }, true, _suppressWildcardExpansion) ?? Enumerable.Empty <PSObject>(); } catch (PSNotSupportedException notSupported) { WriteError(new ErrorRecord(notSupported.ErrorRecord, notSupported)); continue; } catch (DriveNotFoundException driveNotFound) { WriteError(new ErrorRecord(driveNotFound.ErrorRecord, driveNotFound)); continue; } catch (ProviderNotFoundException providerNotFound) { WriteError(new ErrorRecord(providerNotFound.ErrorRecord, providerNotFound)); continue; } catch (ItemNotFoundException pathNotFound) { WriteError(new ErrorRecord(pathNotFound.ErrorRecord, pathNotFound)); continue; } foreach (var item in items) { WriteVerbose("item:" + item.ToString()); if (item.BaseObject is System.IO.FileSystemInfo info) { try { // フルパスからシナリオかどうか判定する WriteVerbose("fullName:" + info.FullName); WriteObject(CardWirthScenario.IsScenarioSummary(info.FullName, ScenarioType, ContainerType)); } catch (Exception) { WriteObject(false); } } } } }
protected override void ProcessRecord() { WriteVerbose("Path:" + String.Join(",", Path)); WriteVerbose("LiteralPath:" + String.Join(",", LiteralPath)); WriteVerbose("_paths:" + String.Join(",", _paths)); WriteVerbose("_suppressWildcardExpansion:" + _suppressWildcardExpansion.ToString()); foreach (string path in _paths) { WriteVerbose("path:" + path); var items = Enumerable.Empty <PSObject>(); try { // Get-Item的なものを呼ぶ items = InvokeProvider.Item.Get(new string[] { path }, true, _suppressWildcardExpansion) ?? Enumerable.Empty <PSObject>(); // Pathの場合、結果は複数返ってくる可能性がある // /path/to/NotExist* -> /path/to/にNotExistが存在しなくてもエラーにはならない // /path/to/NotExist -> /path/to/にNotExistが存在しないとエラーを返す // /path/to/Exist -> /path/to/にExistがあれば、PSObjectが1個入ったEnumerable(リストみたいなもの)が返る // /path/to/Exist* -> /path/to/にExistA, ExistB, ExistCが存在すればPSObjectが3個入ったEnumerableが返る } catch (PSNotSupportedException notSupported) { WriteError(new ErrorRecord(notSupported.ErrorRecord, notSupported)); continue; } catch (DriveNotFoundException driveNotFound) { WriteError(new ErrorRecord(driveNotFound.ErrorRecord, driveNotFound)); continue; } catch (ProviderNotFoundException providerNotFound) { WriteError(new ErrorRecord(providerNotFound.ErrorRecord, providerNotFound)); continue; } catch (ItemNotFoundException pathNotFound) { WriteError(new ErrorRecord(pathNotFound.ErrorRecord, pathNotFound)); continue; } foreach (var item in items) { // System.Management.Automation.PSObject WriteVerbose("item:" + item.ToString()); // ファイルとディレクトリ両方扱いたいのでFileSystemInfoに変換する if (item.BaseObject is System.IO.FileSystemInfo info) { try { // フルパスからシナリオ情報を取得する WriteVerbose("fullName:" + info.FullName); WriteObject(CardWirthScenario.GetScenarioSummary(info.FullName)); } catch (ScenarioNotFoundException ex) { WriteError(new ErrorRecord(ex, "ScenarioNotFoundException", ErrorCategory.ObjectNotFound, info.FullName)); continue; } catch (UnsupportedContainerTypeException ex) { WriteError(new ErrorRecord(ex, "UnsupportedContainerTypeException", ErrorCategory.InvalidArgument, info.FullName)); continue; } catch (InvalidScenarioException ex) { WriteError(new ErrorRecord(ex, "InvalidScenarioException", ErrorCategory.InvalidData, info.FullName)); continue; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "Exception", ErrorCategory.WriteError, info.FullName)); continue; } } } } }
/// <summary> /// The main execution method for the get-childitem command. /// </summary> protected override void ProcessRecord() { if (_paths == null || _paths.Length == 0) { WriteVerbose("path is null or 0 length."); _paths = new string[] { string.Empty }; } WriteVerbose("Path:" + String.Join(",", Path)); WriteVerbose("LiteralPath:" + String.Join(",", LiteralPath)); WriteVerbose("_paths:" + String.Join(",", _paths)); WriteVerbose("_suppressWildcardExpansion:" + _suppressWildcardExpansion.ToString()); WriteVerbose("Classic:" + Classic.ToString()); WriteVerbose("Next:" + Next.ToString()); WriteVerbose("Wsn:" + Wsn.ToString()); WriteVerbose("Directory:" + Directory.ToString()); WriteVerbose("ZipFile:" + ZipFile.ToString()); WriteVerbose("CabFile:" + CabFile.ToString()); WriteVerbose("WsnFile:" + WsnFile.ToString()); foreach (string path in _paths) { WriteVerbose("path:" + path); // バイナリモジュールから呼べるTest-PathやChildItem的なメソッドでLiteralPathフラグが使えないので、 // あらかじめエスケープしたパスを用意しておき必要な場合はそれを使う var escapedPath = System.Text.RegularExpressions.Regex.Replace(path, "([\\[\\]])", "`$1"); WriteVerbose("escapedPath:" + escapedPath); switch (ParameterSetName) { case childrenSet: case literalChildrenSet: var scenarioFullNames = new List <string>(); // `lscw ゴブリンの洞窟`と指定したとき、ChildItemだけだとゴブリンの洞窟以下のファイルに対して // GetScenarioSummaryをしてしまうため、フォルダ自体にGetScenarioSummaryする処理 // -----------------------👇ここから👇----------------------- if (InvokeProvider.Item.Exists(path, true, _suppressWildcardExpansion)) { WriteVerbose("path is exists."); if (InvokeProvider.Item.IsContainer((_suppressWildcardExpansion ? escapedPath : path))) { WriteVerbose("path is directory."); // 上の条件分岐で存在しているディレクトリに対してしかGet-Itemは動かないのでここで例外は起こらないはず var items = InvokeProvider.Item.Get(new string[] { path }, true, _suppressWildcardExpansion) ?? Enumerable.Empty <PSObject>(); foreach (var item in items) { if (item.BaseObject is System.IO.FileSystemInfo info) { try { // フルパスからシナリオ情報を取得する WriteVerbose("fullName:" + info.FullName); var scenarioSummary = CardWirthScenario.GetScenarioSummary(info.FullName); // 次のChildItemで同じフォルダを見る可能性があるので // 処理対象外にするためにシナリオのパスを覚えておく scenarioFullNames.Add(scenarioSummary.FullName); // シナリオ形式のフィルタリング if (Classic && scenarioSummary.ScenarioType != ScenarioType.Classic) { continue; } else if (Next && scenarioSummary.ScenarioType != ScenarioType.Next) { continue; } else if (Wsn && scenarioSummary.ScenarioType != ScenarioType.Wsn) { continue; } // 格納形式のフィルタリング if (Directory && scenarioSummary.ContainerType != ContainerType.Directory) { continue; } else if (ZipFile && scenarioSummary.ContainerType != ContainerType.ZipFile) { continue; } else if (CabFile && scenarioSummary.ContainerType != ContainerType.CabFile) { continue; } else if (WsnFile && scenarioSummary.ContainerType != ContainerType.WsnFile) { continue; } WriteObject(scenarioSummary); } catch (Exception ex) { WriteVerbose("error:" + ex.Message); continue; } } } } } // -----------------------👆ここまで👆----------------------- // ここから指定したパス以下のファイル・フォルダを調査する var childItems = Enumerable.Empty <PSObject>(); try { childItems = InvokeProvider.ChildItem.Get((_suppressWildcardExpansion ? escapedPath : path), _recurse) ?? Enumerable.Empty <PSObject>(); } catch (PSNotSupportedException notSupported) { WriteError(new ErrorRecord(notSupported.ErrorRecord, notSupported)); continue; } catch (DriveNotFoundException driveNotFound) { WriteError(new ErrorRecord(driveNotFound.ErrorRecord, driveNotFound)); continue; } catch (ProviderNotFoundException providerNotFound) { WriteError(new ErrorRecord(providerNotFound.ErrorRecord, providerNotFound)); continue; } catch (ItemNotFoundException pathNotFound) { WriteError(new ErrorRecord(pathNotFound.ErrorRecord, pathNotFound)); continue; } foreach (var childItem in childItems) { WriteVerbose("childItem:" + childItem); if (childItem.BaseObject is System.IO.FileSystemInfo info) { // Get-ChildItemでとってきた要素すべてを調査していてはきりがないのである程度選別する; if (info is System.IO.FileInfo file) { // 拡張子がサポート対象外のファイルの場合、シナリオ情報取得をスキップする var extension = System.IO.Path.GetExtension(file.FullName).ToLower(); if (extension != ".zip" && extension != ".cab" && extension != ".wsn") { WriteVerbose("path is not supported archive file. skipped acquisition of scenario information."); continue; } } // 調査済みパスの場合、シナリオ情報取得をスキップする if (scenarioFullNames.Contains(info.FullName)) { WriteVerbose("path has been investigated. skipped acquisition of scenario information."); continue; } try { // フルパスからシナリオ情報を取得する // TODO:ディレクトリの場合、シナリオではないのならエラー表示を無視したい // 再帰のとき、エラー処理をどうするか考え中 var scenarioSummary = CardWirthScenario.GetScenarioSummary(info.FullName); // シナリオ形式のフィルタリング if (Classic && scenarioSummary.ScenarioType != ScenarioType.Classic) { continue; } else if (Next && scenarioSummary.ScenarioType != ScenarioType.Next) { continue; } else if (Wsn && scenarioSummary.ScenarioType != ScenarioType.Wsn) { continue; } // 格納形式のフィルタリング if (Directory && scenarioSummary.ContainerType != ContainerType.Directory) { continue; } else if (ZipFile && scenarioSummary.ContainerType != ContainerType.ZipFile) { continue; } else if (CabFile && scenarioSummary.ContainerType != ContainerType.CabFile) { continue; } else if (WsnFile && scenarioSummary.ContainerType != ContainerType.WsnFile) { continue; } WriteObject(scenarioSummary); } catch (Exception ex) { WriteVerbose("error:" + ex.Message); continue; } } } break; default: break; } } }