コード例 #1
0
ファイル: EmdrConfig.cs プロジェクト: Ralack/EMDRGatherer
        private ConfigState Serialize()
        {
            FileUtil futl = new FileUtil();

            if (!futl.isConfigDirectoryExists())
            {
                futl.createConfigDirectory();
            }

            try
            {
                if(checkConfig())
                {
                    string filename = futl.getConfigFilePath();

                    FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    XmlSerializer xserial = new XmlSerializer(Attr.GetType());
                    xserial.Serialize(fs, Attr);

                    fs.Flush();
                    fs.Close();

                    return ConfigState.ConfigSaved;
                }
                else
                {
                    return ConfigState.ConfigInvalid;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
ファイル: EmdrConfig.cs プロジェクト: Ralack/EMDRGatherer
        private ConfigState DeSerialize( )
        {
            FileUtil futl = new FileUtil();

            if (futl.isConfigDirectoryExists())
            {
                try
                {
                    string filename = futl.getConfigFilePath();

                    StreamReader rdr = new StreamReader(filename);

                    if (!rdr.EndOfStream)
                    {
                        XmlSerializer xserial = new XmlSerializer(Attr.GetType());
                        Attr = (ConfigAttributes)xserial.Deserialize(rdr);
                        rdr.Close();
                    }
                    else
                    {
                        rdr.Close();
                        return ConfigState.ConfigNotFound;
                    }

                    if (checkConfig())
                    {
                        Attr.isConfiged = true;
                        return ConfigState.ConfigLoaded;
                    }
                    else
                    {
                        Attr.isConfiged = false;
                        return ConfigState.ConfigInvalid;
                    }

                }
                catch (Exception ex)
                {
                    if (ex is FileNotFoundException)
                    {
                        return ConfigState.ConfigNotFound;
                    }
                    throw ex;
                }
            }
            else
                return ConfigState.ConfigNotLoaded;
        }