Esempio n. 1
0
        /**<summary>
         * Object is constructed by serializer with default values,
         * property (which also specified in the XML) value will be overwritten from the XML
         * </summary>
         */
        public static void LoadFileOrDefault(string pathConfigXml, string pathPrefXml)
        {
            // load configuration
            if (FileUtil.XmlDeserialize(pathConfigXml, typeof(Config)) is Config config)
            {
                Configuration = config;

                // restore status
                if (Configuration.RemoteServerType == ServerTypeSS)
                {
                    RemoteServer = ServerManager.ShadowsocksList.FirstOrDefault(
                        server => server.GetId() == config.RemoteServerID);
                }
                else if (Configuration.RemoteServerType == ServerTypeV2Ray)
                {
                    RemoteServer = ServerManager.V2RayList.FirstOrDefault(
                        server => server.GetId() == config.RemoteServerID);
                }
                else
                {
                    RemoteServer = null;
                }
            }
            else
            {
                Configuration = new Config();
            }

            // load appearance
            if (FileUtil.XmlDeserialize(pathPrefXml, typeof(Preference)) is Preference preference)
            {
                Appearance = preference;
            }
            else
            {
                Appearance = new Preference();
            }
        }
Esempio n. 2
0
 public static void WriteFile(string pathPrefXml, Preference preference)
 {
     FileUtil.XmlSerialize(pathPrefXml, preference);
 }