「C#/RFS/コード断片」の編集履歴(バックアップ)一覧に戻る

C#/RFS/コード断片 - (2009/03/07 (土) 17:37:05) のソース

codehighlightを使ってみたかっただけという説もある。
だいぶ前に書いたものだからほぼ他人状態w これから直すところ。

-[[CurrentReplayFolder>C#/RFS/コード断片/CurrentReplayFolder]]
-[[Util>c#/RFS/コード断片/Util]]
-[[EntryManager/c#/RFS/コード断片/EntryManager]]



*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 WindowsFormsApplication1
{
    class EntryManager
    {
        private string[] nicknames = {};

        private string[] paths = {};

        public string[] Nicknames
        {
            get { return nicknames; }
        }

        public string[] Paths
        {
            get { return paths; }
        }

        public void Update()
        {
            paths = Directory.GetDirectories(".", "Replay_*");

            List<string> a = new List<string>();
            foreach (string path in paths)
            {
                string suffix = path.Substring(path.IndexOf('_') + 1);
                a.Add(suffix + ". " + Util.ReadNickname(path));
            }

            nicknames = a.ToArray();
        }

        public void CreateFolder()
        {
            try
            {
                string path = Util.AvailableFolderName();
                Directory.CreateDirectory(path);
            }
            catch (IOException)
            {
                MessageBox.Show("フォルダの作成に失敗しました", "ERROR");
            }
        }

        public void ChangeFolder(int index)
        {
            try
            {
                string path = Util.AvailableFolderName();
                Directory.Move(Util.REPLAY_FOLDER, path);
                Directory.Move(paths[index], Util.REPLAY_FOLDER);
            }
            catch (IOException)
            {
                MessageBox.Show("Replayフォルダのリネームに失敗しました", "ERROR");
            }
        }

        public void MoveReplay(string repname, int index)
        {
            string dest = paths[index] + "\\" + repname;

            if (Directory.Exists(dest))
            {
                MessageBox.Show("リプレイ名が重複してしまいます!", "移動失敗");
            }
            else
            {
                try
                {
                    Directory.Move(Util.REPLAY_FOLDER + "\\" + repname, dest);
                }
                catch (IOException)
                {
                    MessageBox.Show("リプレイのリネームに失敗しました", "ERROR");
                }
            }
        }

        public void DissoluteFolder(int index)
        {
            string target = paths[index];
            string[] srcs = Directory.GetDirectories(target);

            try
            {
                foreach (string src in srcs)
                {
                    int i = src.IndexOf(target) + target.Length + 1;
                    string path0 = Util.REPAY_FOLDER + "\\" + src.Substring(i);
                    string dest = Util.AvailableFolderName(path0);
                    Directory.Move(src, dest);
                }
            }
            catch (IOException)
            {
                MessageBox.Show("リプレイのリネームに失敗しました", "ERROR");
                return;
            }

            if (Directory.GetFiles(target).Length <= 1)
            {
                Directory.Delete(target, true);
            }
            else
            {
                MessageBox.Show("他のファイルがあるので" + target + "の削除は行いません",
                    "他のファイルが残っています");
            }
        }
    }
}
}}

まずメソッドやプロパティを並べてみる:
-Update()
-CreateFolder()
-ChangeFolder(int index)
-MoveReplay(string repname, int index)
-DissoluteFolder(int index)
-string[] Paths
-string[] Nicknames





----