Пример #1
0
 private static bool ReadOldConfig(FileInfo file)
 {
     try
     {
         var          result   = false;
         const string settings = "/configuration/userSettings/Launcher.Properties.Settings/";
         var          xml      = new XmlDocument();
         using (var stream = file.OpenRead())
             xml.Load(stream);
         var lastUrlNodes = xml.SelectNodes(settings + "setting[@name='LastURL']/value");
         if (lastUrlNodes.Count == 1)
         {
             LastUrl = lastUrlNodes[0].InnerText;
             result  = true;
         }
         var redirectsNodes = xml.SelectNodes(settings + "setting[@name='Redirects']/value");
         if (redirectsNodes.Count == 1)
         {
             Redirect = new Redirect(
                 DeserializeRedirectSettings(redirectsNodes[0].InnerXml));
             result = true;
         }
         return(result);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #2
0
        public static void ReadConfig()
        {
            var load  = false;
            var local = ApplicationData.Current.LocalSettings;

            if (local.Values.ContainsKey(VerKey) &&
                local.Values[VerKey] is int version)
            {
                switch (version)
                {
                case 1:
                    if (
                        local.Values.ContainsKey(nameof(LastUrl)) &&
                        local.Values[nameof(LastUrl)] is string lastUrl)
                    {
                        LastUrl = lastUrl;
                    }
                    else
                    {
                        LastUrl = null;
                    }

                    RedirectSetting[]? redirectSettings = null;
                    if (local.Values.ContainsKey(nameof(Redirect)) &&
                        local.Values[nameof(Redirect)] is string redirect)
                    {
                        redirectSettings =
                            DeserializeRedirectSettings(redirect);
                    }
                    Redirect = new Redirect(redirectSettings);

                    load = true;
                    break;
                }
            }
            if (!load)
            {
                foreach (var file in FindOldConfig())
                {
                    if (ReadOldConfig(file))
                    {
                        if (Redirect == null)
                        {
                            Redirect = new Redirect(null);
                        }
                        Save();
                        load = true;
                        break;
                    }
                }
            }
            if (!load)
            {
                Redirect = new Redirect(null);
                Save();
            }
        }