「C#/RFS/コード断片/EntryManager」の編集履歴(バックアップ)一覧はこちら
追加された行は緑色になります。
削除された行は赤色になります。
リプレイフォルダたちを管理するクラス。リプレイフォルダのことをEntryって呼んでた・・・らしいw
#codehighlight(css){{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ReplayFolderSelecter
{
class EntryManager
{
private string[] nicknames = { };
private string[] paths = { };
public string[] Paths
{
get { return paths; }
}
public string[] GetNicknames()
{
return (string[])nicknames.Clone();
}
public string GetNickname(int index)
{
return nicknames[index];
}
public void SetNickname(string name, int index)
{
try
{
Util.WriteNickname(paths[index], name);
nicknames[index] = name;
}
catch (IOException)
{
MessageBox.Show("ニックネームの設定に失敗しました", "ERROR");
}
}
public void Update()
{
paths = Directory.GetDirectories(".", "Replay_*");
List<string> a = new List<string>();
foreach (string path in paths)
{
a.Add(Util.ReadNickname(path));
}
nicknames = a.ToArray();
}
public void MoveReplay(string repname, int index)
{
string dest = paths[index] + "\\" + repname;
if (Directory.Exists(dest))
{
MessageBox.Show("リプレイ名が重複してしまいます!", "ERROR");
}
else
{
try
{
Directory.Move(Util.REPLAY_FOLDER + "\\" + repname, dest);
}
catch (IOException)
{
MessageBox.Show("リプレイの移動に失敗しました", "ERROR");
}
}
}
public void CreateFolder()
{
try
{
string path = Util.AvailableFolderName("Replay", false);
Directory.CreateDirectory(path);
}
catch (IOException)
{
MessageBox.Show("フォルダの作成に失敗しました", "ERROR");
}
}
public void SwapFolder(int index)
{
string tmppath = Util.AvailableFolderName("Replay", true);
try
{
Directory.Move(paths[index], tmppath);
Directory.Move(Util.REPLAY_FOLDER, paths[index]);
}
catch(IOException){
MessageBox.Show("Replayフォルダのリネームに失敗しました", "ERROR");
return;
}
try
{
Directory.Move(tmppath, Util.REPLAY_FOLDER);
}
catch (IOException)
{
string msg =
"カレントリプレイフォルダと" + paths[index] + "の入れ替え中に\n"
+ "リネームの失敗が発生しました。" + paths[index] + "が元のリプレイフォルダです。\n"
+ "お手数ですが、原因を取り除いたあと手動で戻してください";
MessageBox.Show(msg, "ERROR");
Environment.Exit(0);
}
}
public void DissoluteFolder(int index)
{
string path = paths[index];
string nickname = nicknames[index];
bool f = Util.CleanUp(path, nickname);
if (f)
{
MessageBox.Show("正常に移動を完了しました", "移動成功");
string msg =
"続けて、'" + nickname + "' のフォルダを削除しますか?\n"
+ "(注意: 中にファイルが残っていても削除されます)";
if (Util.YesNo(msg, "フォルダの完全消去"))
{
try
{
Directory.Delete(path, true);
Update();
}
catch (IOException)
{
MessageBox.Show(path + "の削除に失敗しました", "ERROR");
}
}
}
}
}
}
}}
まずメソッドやプロパティを並べてみる:
-Update()
-CreateFolder()
-SwapFolder(int index)
-MoveReplay(string repname, int index)
-DissoluteFolder(int index)
-string[] GetNicknames()
-string GetNickname(int index)
-void SetNickname(string name, int index)
-string[] Paths
----
リプレイフォルダたちを管理するクラス。リプレイフォルダのことをEntryって呼んでた・・・らしいw
#codehighlight(css){{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ReplayFolderSelecter
{
class EntryManager
{
private string[] nicknames = { };
private string[] paths = { };
public string[] Paths
{
get { return paths; }
}
public string[] GetNicknames()
{
return (string[])nicknames.Clone();
}
public string GetNickname(int index)
{
return nicknames[index];
}
public void SetNickname(string name, int index)
{
try
{
Util.WriteNickname(paths[index], name);
nicknames[index] = name;
}
catch (IOException)
{
MessageBox.Show("ニックネームの設定に失敗しました", "ERROR");
}
}
public void Update()
{
paths = Directory.GetDirectories(".", "Replay_*");
List<string> a = new List<string>();
foreach (string path in paths)
{
a.Add(Util.ReadNickname(path));
}
nicknames = a.ToArray();
}
public void MoveReplay(string repname, int index)
{
string dest = paths[index] + "\\" + repname;
if (Directory.Exists(dest))
{
MessageBox.Show("リプレイ名が重複してしまいます!", "ERROR");
}
else
{
try
{
Directory.Move(Util.REPLAY_FOLDER + "\\" + repname, dest);
}
catch (IOException)
{
MessageBox.Show("リプレイの移動に失敗しました", "ERROR");
}
}
}
public void CreateFolder()
{
try
{
string path = Util.AvailableFolderName("Replay", false);
Directory.CreateDirectory(path);
}
catch (IOException)
{
MessageBox.Show("フォルダの作成に失敗しました", "ERROR");
}
}
public void SwapFolder(int index)
{
string tmppath = Util.AvailableFolderName("Replay", false);
try
{
Directory.Move(paths[index], tmppath);
Directory.Move(Util.REPLAY_FOLDER, paths[index]);
}
catch(IOException){
MessageBox.Show("Replayフォルダのリネームに失敗しました", "ERROR");
return;
}
try
{
Directory.Move(tmppath, Util.REPLAY_FOLDER);
}
catch (IOException)
{
string msg =
"カレントリプレイフォルダと" + paths[index] + "の入れ替え中に\n"
+ "リネームの失敗が発生しました。" + paths[index] + "が元のリプレイフォルダです。\n"
+ "お手数ですが、原因を取り除いたあと手動で戻してください";
MessageBox.Show(msg, "ERROR");
Environment.Exit(0);
}
}
public void DissoluteFolder(int index)
{
string path = paths[index];
string nickname = nicknames[index];
bool f = Util.CleanUp(path, nickname);
if (f)
{
MessageBox.Show("正常に移動を完了しました", "移動成功");
string msg =
"続けて、'" + nickname + "' のフォルダを削除しますか?\n"
+ "(注意: 中にファイルが残っていても削除されます)";
if (Util.YesNo(msg, "フォルダの完全消去"))
{
try
{
Directory.Delete(path, true);
Update();
}
catch (IOException)
{
MessageBox.Show(path + "の削除に失敗しました", "ERROR");
}
}
}
}
}
}
}}
まずメソッドやプロパティを並べてみる:
-Update()
-CreateFolder()
-SwapFolder(int index)
-MoveReplay(string repname, int index)
-DissoluteFolder(int index)
-string[] GetNicknames()
-string GetNickname(int index)
-void SetNickname(string name, int index)
-string[] Paths
----