最近書き直したもの。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace ReplayFolderSelecter
{
    class CurrentReplayFolder
    {
        private string[] replays;
 
        private string nickname;
 
        public string[] Replays
        {
            get
            {
                return replays;
            }
        }
 
        public string Nickname
        {
            get
            {
                return nickname;
            }
            set
            {
                try
                {
                    Util.WriteNickname(Util.REPLAY_FOLDER, value);
                    nickname = value;
                }
                catch (IOException)
                {
                    MessageBox.Show("ニックネームの設定に失敗しました", "ERROR");
                }
            }
        }
 
        public void Update()
        {
            string[] dirs = Directory.GetDirectories(Util.REPLAY_FOLDER, "*");
            List<string> a = new List<string>();
 
            foreach (string d in dirs)
            {
                if (File.Exists(d + "\\_Header.ini"))
                {
                    a.Add(d.Substring(d.LastIndexOf('\\') + 1));
                }
            }
 
            replays = a.ToArray();
            nickname = Util.ReadNickname(Util.REPLAY_FOLDER);
        }
 
        public void RenameReplay(string oldname, string newname)
        {
            string dest = Util.REPLAY_FOLDER + "\\" + newname;
 
            try
            {
                if (Directory.Exists(dest))
                {
                    MessageBox.Show("リプレイ名が重複してしまいます!", "ERROR");
                }
                else
                {
                    Directory.Move(Util.REPLAY_FOLDER + "\\" + oldname, dest);
                }
            }
            catch (IOException)
            {
                MessageBox.Show("リプレイのリネームに失敗しました", "ERROR");
            }
        }
 
        public void RemoveReplay(string repname)
        {
            DialogResult result = MessageBox.Show(
                "本当に '" + repname + "' を削除しますか?",
                "削除の確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
 
            if (result == DialogResult.Yes)
            {
                string path = Util.REPLAY_FOLDER + "\\" + repname;
                try
                {
                    Directory.Delete(path, true);
                }
                catch (IOException)
                {
                    MessageBox.Show(path + "の削除に失敗しました", "ERROR");
                }
            }
        }
    }
}
 

  • Update()
  • RenameReplay(string oldname, string newname)
  • RemoveReplay(string repname)
  • string[] Replays
  • string Nickname






最終更新:2009年03月05日 21:51