예제 #1
0
                /// <summary>
                /// XMLファイルからIDとパスワードを読み込み、ハッシュテーブル化する
                /// </summary>
                ///
                /// <param name="string">読み込むテキストファイル名</param>
                /// <returns>IDをキー、Passwodを値としたハッシュテーブル</returns>
                public static ArrayList loadAccountKey(string filename)
                {
                    string filepath = "";

                    if (Path.IsPathRooted(filename))
                    {
                        filepath = filename;
                        filename = Path.GetFileName(filename);
                    }
                    else
                    {
                        filepath = Path.GetFullPath(@".\" + filename);
                    }
                    if (File.Exists(filepath))
                    {
                        try
                        {
                            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlAccount));
                            System.IO.FileStream fs        = new System.IO.FileStream(filepath, System.IO.FileMode.Open);
                            XmlMyAccounts        loadDatas = (XmlMyAccounts)serializer.Deserialize(fs);

                            XmlAccount[] dataPack = (XmlAccount[])loadDatas.AccountList;
                            foreach (XmlAccount data in dataPack)
                            {
                                Accounts.AccountProperties props = new Accounts.AccountProperties();
                                props.ID       = data.ID;
                                props.Password = Common.DecryptString(data.Password, AccountController.MasterKey);
                                if (data.Site.Equals(null))
                                {
                                    props.Site = Accounts.AccountProperties.LoginSite.Official;
                                }
                                else
                                {
                                    try
                                    {
                                        props.Site = (Accounts.AccountProperties.LoginSite)data.Site;
                                    }
                                    catch (Exception e)
                                    {
                                        SimpleLogger.WriteLine(e.Message);
                                        props.Site = Accounts.AccountProperties.LoginSite.Official;
                                    }
                                }

                                AccountData.Add(props);
                            }
                            fs.Close();

                            return(AccountData);
                        }
                        catch (FileLoadException ex)
                        {
                            SimpleLogger.WriteLine(ex.Message);
                            MessageBox.Show("例外エラー:\nファイルの読み込み二失敗しました。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return(AccountData);
                        }
                    }
                    else
                    {
                        MessageBox.Show("アカウント情報ファイルを読み込めませんでした。" + Environment.NewLine + "'" + filepath + "'", "Trickster Tools", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(AccountData);
                    }
                }
예제 #2
0
                /// <summary>
                /// XMLファイルからIDとパスワードを読み込み、ハッシュテーブル化する
                /// </summary>
                ///
                /// <param name="filename">読み込むXMLファイル名</param>
                /// <param name="keyword">アカウントデータを読み込むキー</param>
                /// <returns>IDをキー、Passwodを値としたハッシュテーブル</returns>
                public void loadAccounts(string filename, string keyword)
                {
                    string filepath = "";

                    if (Path.IsPathRooted(filename))
                    {
                        filepath = filename;
                        filename = Path.GetFileName(filename);
                    }
                    else
                    {
                        filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename);
                    }
                    if (File.Exists(filepath))
                    {
                        try
                        {
                            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlTricksterRoot));
                            System.IO.FileStream fs           = new System.IO.FileStream(filepath, System.IO.FileMode.Open);
                            XmlTricksterRoot     XmlRoot      = (XmlTricksterRoot)serializer.Deserialize(fs);
                            XmlMyAccounts        accountDatas = new XmlMyAccounts();
                            accountDatas = XmlRoot.MyAccount;
                            String PasswordDecryptKey;
                            PasswordDecryptKey = getKeyword(accountDatas.EncryptKey);

                            if (AccountController.MasterKey != PasswordDecryptKey)
                            {
                                SimpleLogger.WriteLine("failed to match MasterKey and EncryptedKey in account data.");
                                MessageBox.Show("暗号化キーワードが一致しないためアカウント情報を読み込めませんでした。", "アカウント情報読み込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            AccountController.isLoadedAccount = true;

                            XmlAccount[] dataPack = (XmlAccount[])accountDatas.AccountList;

                            foreach (XmlAccount data in dataPack)
                            {
                                Accounts.AccountProperties props = new Accounts.AccountProperties();
                                //AccountData[data.ID] = Common.DecryptString(data.Password, AccountController.MasterKey);
                                props.ID       = data.ID;
                                props.Password = Common.DecryptString(data.Password, PasswordDecryptKey);
                                if (data.Site.Equals(null))
                                {
                                    props.Site = Accounts.AccountProperties.LoginSite.Official;
                                }
                                else
                                {
                                    try
                                    {
                                        props.Site = (Accounts.AccountProperties.LoginSite)data.Site;
                                    }catch (Exception e) {
                                        SimpleLogger.WriteLine(e.Message);
                                        props.Site = Accounts.AccountProperties.LoginSite.Official;
                                    }
                                }

                                AccountData.Add(props);
                            }
                            fs.Close();
                        }
                        catch (FileLoadException fle)
                        {
                            SimpleLogger.WriteLine(fle.GetType().ToString() + Environment.NewLine + fle.Message);
                            //MessageBox.Show("例外エラー:\nファイルの読み込みに失敗しました。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //return;
                            throw fle;
                        }
                        catch (System.Xml.XmlException xe)
                        {
                            SimpleLogger.WriteLine(xe.GetType().ToString() + Environment.NewLine + xe.Message);
                            //MessageBox.Show("例外エラー:\nデータの処理に失敗しました。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //return;
                            throw xe;
                        }
                        catch (System.UnauthorizedAccessException uae)
                        {
                            SimpleLogger.WriteLine(uae.GetType().ToString() + Environment.NewLine + uae.Message);
                            //MessageBox.Show("例外エラー:\nアカウントファイルが読み取り専用か、権限がないため読み込めませんでした。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //return;
                            throw uae;
                        }
                        catch (System.InvalidOperationException ioe)
                        {
                            SimpleLogger.WriteLine(ioe.GetType().ToString() + Environment.NewLine + ioe.Message);
                            //MessageBox.Show("例外エラー:\n無効なメソッドの呼び出しが行われました。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //return;
                            throw ioe;
                        }
                    }
                    else
                    {
                        SimpleLogger.WriteLine("account file 'accounts.dat' could not read/found.");
                        MessageBox.Show("アカウント情報ファイルを読み込めませんでした。" + Environment.NewLine + "'" + filepath + "'", "Trickster Tools", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        isLoadedAccount = false;
                        return;
                    }
                }
예제 #3
0
                /// <summary>
                /// XML�t�@�C������ID�ƃp�X���[�h��ǂݍ��݁A�n�b�V���e�[�u��������
                /// </summary>
                /// 
                /// <param name="filename">�ǂݍ���XML�t�@�C����</param>
                /// <param name="keyword">�A�J�E���g�f�[�^��ǂݍ��ރL�[</param>
                /// <returns>ID��L�[�APasswod��l�Ƃ����n�b�V���e�[�u��</returns>
                public void loadAccounts(string filename, string keyword)
                {
                    string filepath = "";
                    if (Path.IsPathRooted(filename))
                    {
                        filepath = filename;
                        filename = Path.GetFileName(filename);
                    }
                    else
                    {
                        filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename);
                    }
                    if (File.Exists(filepath))
                    {
                        try
                        {
                            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlTricksterRoot));
                            System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open);
                            XmlTricksterRoot XmlRoot = (XmlTricksterRoot)serializer.Deserialize(fs);
                            XmlMyAccounts accountDatas = new XmlMyAccounts();
                            accountDatas = XmlRoot.MyAccount;
                            String PasswordDecryptKey;
                            PasswordDecryptKey = getKeyword(accountDatas.EncryptKey);

                            if (AccountController.MasterKey != PasswordDecryptKey)
                            {
                                SimpleLogger.WriteLine("failed to match MasterKey and EncryptedKey in account data.");
                                MessageBox.Show("�Í����L�[���[�h����v���Ȃ����߃A�J�E���g����ǂݍ��߂܂���ł����B", "�A�J�E���g���ǂݍ��݃G���[", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            AccountController.isLoadedAccount = true;

                            XmlAccount[] dataPack = (XmlAccount[])accountDatas.AccountList;

                            foreach (XmlAccount data in dataPack)
                            {
                                Accounts.AccountProperties props = new Accounts.AccountProperties();
                                //AccountData[data.ID] = Common.DecryptString(data.Password, AccountController.MasterKey);
                                props.ID = data.ID;
                                props.Password = Common.DecryptString(data.Password, PasswordDecryptKey);
                                if (data.Site.Equals(null))
                                {
                                    props.Site = Accounts.AccountProperties.LoginSite.Official;
                                }
                                else
                                {
                                    try
                                    {
                                        props.Site = (Accounts.AccountProperties.LoginSite)data.Site;
                                    }catch(Exception e){
                                        SimpleLogger.WriteLine(e.Message);
                                        props.Site = Accounts.AccountProperties.LoginSite.Official;
                                    }
                                }

                                AccountData.Add(props);
                            }
                            fs.Close();
                        }
                        catch (FileLoadException fle)
                        {
                            SimpleLogger.WriteLine(fle.GetType().ToString() + Environment.NewLine + fle.Message);
                            //MessageBox.Show("��O�G���[:\n�t�@�C���̓ǂݍ��݂Ɏ��s���܂����B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //return;
                            throw fle;
                        }
                        catch (System.Xml.XmlException xe)
                        {
                            SimpleLogger.WriteLine(xe.GetType().ToString() + Environment.NewLine + xe.Message);
                            //MessageBox.Show("��O�G���[:\n�f�[�^�̏����Ɏ��s���܂����B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //return;
                            throw xe;
                        }
                        catch (System.UnauthorizedAccessException uae)
                        {
                            SimpleLogger.WriteLine(uae.GetType().ToString() + Environment.NewLine + uae.Message);
                            //MessageBox.Show("��O�G���[:\n�A�J�E���g�t�@�C�����ǂݎ���p���A�������Ȃ����ߓǂݍ��߂܂���ł����B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //return;
                            throw uae;
                        }
                        catch (System.InvalidOperationException ioe)
                        {
                            SimpleLogger.WriteLine(ioe.GetType().ToString() + Environment.NewLine + ioe.Message);
                            //MessageBox.Show("��O�G���[:\n�����ȃ��\�b�h�̌Ăяo�����s���܂����B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //return;
                            throw ioe;
                        }
                    }
                    else
                    {
                        SimpleLogger.WriteLine("account file 'accounts.dat' could not read/found.");
                        MessageBox.Show("�A�J�E���g���t�@�C����ǂݍ��߂܂���ł����B" + Environment.NewLine + "'" + filepath + "'", "Trickster Tools", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        isLoadedAccount = false;
                        return;
                    }
                }
예제 #4
0
                public void saveAccounts(string filename, string keyword)
                {
                    string PasswordEncryptKey;

                    XmlAccount[] config = new XmlAccount[AccountData.Count];

                    PasswordEncryptKey = setKeyword(keyword);
                    IEnumerator ienum = AccountData.GetEnumerator();
                    int         i     = 0;

                    while (ienum.MoveNext())
                    {
                        Accounts.AccountProperties acprop = (Accounts.AccountProperties)ienum.Current;
                        config[i]          = new XmlAccount();
                        config[i].ID       = acprop.ID;
                        config[i].Password = Common.EncryptString(acprop.Password, keyword);
                        config[i].Site     = (int)acprop.Site;
                        i++;
                    }
                    XmlMyAccounts accountdatas = new XmlMyAccounts();

                    accountdatas.AccountList = config;
                    accountdatas.EncryptKey  = PasswordEncryptKey;

                    XmlTricksterRoot XmlRoot = new XmlTricksterRoot();

                    XmlRoot.MyAccount = accountdatas;


                    string filepath = "";

                    if (Path.IsPathRooted(filename))
                    {
                        filepath = filename;
                        filename = Path.GetFileName(filename);
                    }
                    else
                    {
                        filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename);
                    }

                    if (!File.Exists(filepath))
                    {
                        // ファイルがなければ作成
                        FileStream fs = new FileStream(filepath, FileMode.Create);
                        fs.Close();
                    }

                    FileInfo fi = new FileInfo(filepath);

                    if (fi.IsReadOnly)
                    {
                        SimpleLogger.WriteLine("could not write to file \"" + filepath + "\"");
                        MessageBox.Show("アカウント情報ファイルは読み取り専用のため、保存できません。", "TricksterTools", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (AccountData.Count > 0)
                    {
                        try
                        {
                            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlTricksterRoot));
                            FileStream fs = new FileStream(filepath, FileMode.Create);
                            serializer.Serialize(fs, XmlRoot);
                            fs.Close();
                        }

                        /*
                         * catch (System.Security.SecurityException se)
                         * {
                         *  SimpleLogger.WriteLine(se.GetType().ToString() + Environment.NewLine + se.Message);
                         *  //MessageBox.Show("例外エラー:\nセキュリティエラーです。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         *  throw se;
                         * }
                         */
                        catch (System.IO.IOException ioe)
                        {
                            SimpleLogger.WriteLine(ioe.GetType().ToString() + Environment.NewLine + ioe.Message);
                            //MessageBox.Show("例外エラー:\n入出力時にエラーが発生しました。", "IOException error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw ioe;
                        }
                        catch (System.Xml.XmlException xe)
                        {
                            SimpleLogger.WriteLine(xe.GetType().ToString() + Environment.NewLine + xe.Message);
                            //MessageBox.Show("例外エラー:\nアカウント情報読み込みエラー", "XmlException error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw xe;
                        }
                        catch (System.Exception e)
                        {
                            SimpleLogger.WriteLine(e.GetType().ToString() + Environment.NewLine + e.Message);
                            //MessageBox.Show("例外エラー:\n原因の特定ができませんでした。", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw e;
                        }
                    }
                }
예제 #5
0
                public void saveAccounts(string filename, string keyword)
                {
                    string PasswordEncryptKey;
                    XmlAccount[] config = new XmlAccount[AccountData.Count];

                    PasswordEncryptKey = setKeyword(keyword);
                    IEnumerator ienum = AccountData.GetEnumerator();
                    int i = 0;
                    while(ienum.MoveNext())
                    {
                        Accounts.AccountProperties acprop = (Accounts.AccountProperties)ienum.Current;
                        config[i] = new XmlAccount();
                        config[i].ID = acprop.ID;
                        config[i].Password = Common.EncryptString(acprop.Password, keyword);
                        config[i].Site = (int)acprop.Site;
                        i++;
                    }
                    XmlMyAccounts accountdatas = new XmlMyAccounts();
                    accountdatas.AccountList = config;
                    accountdatas.EncryptKey = PasswordEncryptKey;

                    XmlTricksterRoot XmlRoot = new XmlTricksterRoot();
                    XmlRoot.MyAccount = accountdatas;

                    string filepath = "";
                    if (Path.IsPathRooted(filename))
                    {
                        filepath = filename;
                        filename = Path.GetFileName(filename);
                    }
                    else
                    {
                        filepath = Path.GetFullPath(Environment.CurrentDirectory + @"\" + filename);
                    }

                    if (!File.Exists(filepath))
                    {
                        // �t�@�C�����Ȃ���΍쐬
                        FileStream fs = new FileStream(filepath, FileMode.Create);
                        fs.Close();
                    }

                    FileInfo fi = new FileInfo(filepath);
                    if (fi.IsReadOnly)
                    {
                        SimpleLogger.WriteLine("could not write to file \"" + filepath + "\"");
                        MessageBox.Show("�A�J�E���g���t�@�C���͓ǂݎ���p�̂��߁A�ۑ��ł��܂���B", "TricksterTools", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (AccountData.Count > 0)
                    {
                        try
                        {
                            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlTricksterRoot));
                            FileStream fs = new FileStream(filepath, FileMode.Create);
                            serializer.Serialize(fs, XmlRoot);
                            fs.Close();
                        }
                        /*
                        catch (System.Security.SecurityException se)
                        {
                            SimpleLogger.WriteLine(se.GetType().ToString() + Environment.NewLine + se.Message);
                            //MessageBox.Show("��O�G���[:\n�Z�L�����e�B�G���[�ł��B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw se;
                        }
                        */
                        catch (System.IO.IOException ioe)
                        {
                            SimpleLogger.WriteLine(ioe.GetType().ToString() + Environment.NewLine + ioe.Message);
                            //MessageBox.Show("��O�G���[:\n���o�͎��ɃG���[���������܂����B", "IOException error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw ioe;
                        }
                        catch (System.Xml.XmlException xe)
                        {
                            SimpleLogger.WriteLine(xe.GetType().ToString() + Environment.NewLine + xe.Message);
                            //MessageBox.Show("��O�G���[:\n�A�J�E���g���ǂݍ��݃G���[", "XmlException error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw xe;
                        }
                        catch (System.Exception e)
                        {
                            SimpleLogger.WriteLine(e.GetType().ToString() + Environment.NewLine + e.Message);
                            //MessageBox.Show("��O�G���[:\n�����̓��肪�ł��܂���ł����B", "Exceptional error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw e;
                        }
                    }
                }