/// <summary> /// シェル情報の一括読み込み /// </summary> public virtual void Load(int sakuraSurfaceId, int keroSurfaceId) { // 既存の値はクリア ListItems.Clear(); // シェルフォルダを列挙 foreach (var subDir in Directory.GetDirectories(Path.Combine(GhostDirPath, "shell"))) { // 隠しフォルダの場合はスキップ var dirInfo = new DirectoryInfo(subDir); if ((dirInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } var descriptPath = Path.Combine(subDir, "descript.txt"); // descript.txt が存在しないならスキップ if (!File.Exists(descriptPath)) { continue; } var item = new ListItem() { DirPath = subDir }; try { // シェルを読み込み item.Shell = ExplorerShell.Load(subDir, sakuraSurfaceId, keroSurfaceId); item.Name = item.Shell.Name; } catch (UnhandlableShellException ex) { // 処理不可能なシェル item.ErrorMessage = ex.FriendlyMessage; } // シェルの読み込みに失敗した場合、Descript.txtのみ読み込み、名前の取得を試みる if (item.Shell == null) { var descript = DescriptText.Load(descriptPath); item.Name = descript.Get("name"); } ListItems.Add(item); } // 最後に名前+フォルダパス順でソート ListItems = ListItems.OrderBy(s => Tuple.Create(s.Name, s.DirPath)).ToList(); }
public override void Load() { base.Load(); // explorer2\descript.txt 読み込み (存在すれば) Explorer2Descript = null; if (File.Exists(Explorer2DescriptPath)) { Explorer2Descript = DescriptText.Load(Explorer2DescriptPath); } // character_descript.txt があれば読み込み CharacterDescript = null; if (File.Exists(CharacterDescriptPath)) { CharacterDescript = File.ReadAllText(CharacterDescriptPath, Encoding.UTF8); } }
/// <summary> /// 起動後の初期設定 (設定読み込み、ゴースト情報読み込みなど) /// </summary> protected virtual void Setup() { // 既存情報クリア lstGhost.Clear(); imgListFace.Images.Clear(); // FMO情報更新 UpdateFMOInfo(); // この時点でSSPのパスが特定できない場合は、SSPが起動していないためエラー // コマンドライン引数を解釈 var args = Environment.GetCommandLineArgs().ToList(); args.RemoveAt(0); // 先頭はexe名のため削除 var caller = args.FirstOrDefault(); // 呼び出し元ゴースト (id or "unspecified") 省略された場合はunspecified扱い if (args.Any()) { args.RemoveAt(0); // 先頭削除 } var specifiedSSPDirPath = args.FirstOrDefault(); // SSPが存在するフォルダパス if (!string.IsNullOrWhiteSpace(specifiedSSPDirPath)) { if (!Directory.Exists(specifiedSSPDirPath)) { MessageBox.Show("起動パラメータで指定されたSSPフォルダが見つかりませんでした。\n" + specifiedSSPDirPath , "エラー" , MessageBoxButtons.OK , MessageBoxIcon.Error); Application.Exit(); return; } SSPDirPath = specifiedSSPDirPath; } if (args.Any()) { args.RemoveAt(0); // 先頭削除 } // この時点でSSPパスが特定できていない場合はエラー if (SSPDirPath == null) { MessageBox.Show("SSPが見つかりませんでした。\nゴーストエクスプローラ通は、SSPが起動している状態で実行するか、もしくはWindowsのスタートメニューから実行する必要があります。" , "エラー" , MessageBoxButtons.OK , MessageBoxIcon.Error); Application.Exit(); return; } SakuraFMOData target = null; if (!string.IsNullOrWhiteSpace(caller)) { var matched = Regex.Match(caller, @"^id:(.+?)\z"); if (matched.Success) { // idが指定された場合、そのidと一致するゴースト情報を探す var id = matched.Groups[1].Value.Trim(); target = FMOGhostList.FirstOrDefault(g => g.Id == id); } } if (caller == "unspecified" || string.IsNullOrWhiteSpace(caller)) { // "unspecified" が指定された場合、現在起動しているゴーストのうち、ランダムに1体を呼び出し元とする if (FMOGhostList.Any()) { var rand = new Random(); target = FMOGhostList[rand.Next(0, FMOGhostList.Count - 1)]; } } // SSPのapp.datからゴーストフォルダの設定を取得 var ghostDirPaths = new List <string>(); var appDataPath = Path.Combine(SSPDirPath, @"data\profile\app.dat"); if (File.Exists(appDataPath)) { // descript.txtと同じフォーマット var appData = DescriptText.Load(appDataPath); // path.ghost.Num を取得 var ghostNumStr = appData.Get("path.ghost.Num"); int ghostNum; if (ghostNumStr != null && int.TryParse(ghostNumStr, out ghostNum)) { // ゴーストパスを1つずつ取得して追加 for (var i = 0; i < ghostNum; i++) { var dirPath = appData.Get(string.Format("path.ghost.{0}", i)); if (dirPath != null) { // 最初が "." から始まっている場合は相対パスとみなして、絶対パスに変換 if (dirPath.StartsWith(".")) { dirPath = Path.GetFullPath(Path.Combine(SSPDirPath, dirPath)); } // 存在するなら追加 if (Directory.Exists(dirPath)) { ghostDirPaths.Add(dirPath); } } } } } // ゴーストフォルダ選択パスの設定 foreach (var dirPath in ghostDirPaths) { var trimmedPath = dirPath.TrimEnd('\\'); var label = string.Format("{0} [{1}]", Path.GetFileName(trimmedPath), trimmedPath); cmbGhostDir.Items.Add(new DropDownItem() { Value = trimmedPath, Label = label }); } // パスが複数ない場合は、コンボボックス非表示 if (ghostDirPaths.Count == 1) { lstGhost.Height += lstGhost.Top; lstGhost.Top = 0; cmbGhostDir.Visible = false; } // 呼び出し元の情報をプロパティにセット if (target != null) { CallerId = target.Id; CallerSakuraName = target.Name; CallerKeroName = target.KeroName; CallerHWnd = (IntPtr)target.HWnd; } // ボタンラベル変更 BtnChange.Text = string.Format("{0}から切り替え", CallerSakuraName); // チェックボックスの位置移動 ChkCloseAfterChange.Left = BtnChange.Left + 1; // イメージリストに不在アイコンを追加 AbsenceImageKeys.Clear(); foreach (var path in Directory.GetFiles(Path.Combine(Util.GetAppDirPath(), @"res\absence_icon"), "*.png")) { var fileName = Path.GetFileName(path); imgListFace.Images.Add(fileName, new Bitmap(path)); AbsenceImageKeys.Add(fileName); } // 最終起動時の記録があり、かつ最終起動時とバージョンが異なる場合は、キャッシュをすべて破棄 if (CurrentProfile.LastBootVersion != null && Util.GetVersion() != CurrentProfile.LastBootVersion) { Directory.Delete(Util.GetCacheDirPath(), recursive: true); } // 最終起動情報をセットして、Profileを保存 CurrentProfile.LastBootVersion = Util.GetVersion(); Util.SaveProfile(CurrentProfile); // ゴーストフォルダ選択ドロップダウンの項目を選択 // 前回の選択フォルダと一致するものがあればそれを選択 // なければ先頭項目を選択 { var lastUseIndex = -1; for (var i = 0; i < cmbGhostDir.Items.Count; i++) { var item = (DropDownItem)cmbGhostDir.Items[i]; if (item.Value == CurrentProfile.LastUsePath) { lastUseIndex = i; break; } } if (lastUseIndex >= 0) { cmbGhostDir.SelectedIndex = lastUseIndex; } else { cmbGhostDir.SelectedIndex = 0; } } // ソート選択ドロップダウンの項目を選択 // 前回の選択フォルダと一致するものがあればそれを選択 // なければ先頭項目を選択 { var lastSortIndex = -1; for (var i = 0; i < cmbSort.Items.Count; i++) { var item = (DropDownItem)cmbSort.Items[i]; if (item.Value == CurrentProfile.LastSortType) { lastSortIndex = i; break; } } if (lastSortIndex >= 0) { cmbSort.SelectedIndex = lastSortIndex; } else { cmbSort.SelectedIndex = 0; } } // ゴースト情報の読み込みと一覧表示更新 UpdateGhostList(); }