Esempio n. 1
0
        private void CheckUpdate()
        {
            string dir    = AppDomain.CurrentDomain.BaseDirectory;
            string file   = Path.GetFileName(Assembly.GetEntryAssembly()?.Location);
            var    dllist = new XDocument();

            if (File.Exists($"{dir}/lol.exe"))
            {
                File.Delete($"{dir}/lol.exe");
            }

            if (File.Exists($"{dir}/AU.exe"))
            {
                File.Delete($"{dir}/AU.exe");
            }

            try
            {
                dllist = XDocument.Load(ModLinks);
            }
            catch (Exception)
            {
                var form = new ConnectionFailedForm(this);
                form.Closed += Form4_Closed;
                Hide();
                form.ShowDialog();
            }

            XElement installer = dllist.Element("ModLinks")?.Element("Installer");

            // If the SHA1s are non-equal, update.
            if (installer == null || SHA1Equals($"{dir}/{file}", installer.Element("SHA1")?.Value))
            {
                return;
            }

            var dl = new WebClient();

            dl.DownloadFile
            (
                new Uri
                (
                    installer.Element("AULink")?.Value ?? throw new NoNullAllowedException("AULink Missing!")
                ),
                $"{dir}/AU.exe"
            );
            var process = new Process
            {
                StartInfo =
                {
                    FileName  = $"{dir}/AU.exe",
                    Arguments = $"\"{dir}\" {installer.Element("Link")?.Value} {file}"
                }
            };

            process.Start();
            Application.Exit();
        }
Esempio n. 2
0
        private void FillModsList()
        {
            XDocument dllist;

            try
            {
                dllist = XDocument.Load(ModLinks);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                var form4 = new ConnectionFailedForm(this);
                form4.Closed += Form4_Closed;
                Hide();
                form4.ShowDialog();
                return;
            }

            XElement[] mods = dllist.Element("ModLinks")?.Element("ModList")?.Elements("ModLink").ToArray();

            if (mods == null)
            {
                return;
            }

            foreach (XElement mod in mods)
            {
                switch (mod.Element("Name")?.Value)
                {
                case "Modding API Windows":
                    _apiLink      = OS == "Windows" ? mod.Element("Link")?.Value : mod.Element("UnixLink")?.Value;
                    _apiSha1      = mod.Element("Files")?.Element("File")?.Element("SHA1")?.Value;
                    _currentPatch = mod.Element("Files")?.Element("File")?.Element("Patch")?.Value;
                    break;

                default:
                    _modsList.Add
                    (
                        new Mod
                    {
                        Name  = mod.Element("Name")?.Value,
                        Link  = mod.Element("Link")?.Value,
                        Files = mod.Element("Files")
                                ?.Elements("File")
                                .ToDictionary
                                (
                            element => element.Element("Name")?.Value,
                            element => element.Element("SHA1")?.Value
                                ),
                        Dependencies = mod.Element("Dependencies")
                                       ?.Elements("string")
                                       .Select(dependency => dependency.Value)
                                       .ToList(),
                        Optional = mod.Element("Optional")
                                   ?.Elements("string")
                                   .Select(dependency => dependency.Value)
                                   .ToList()
                                   ?? new List <string>()
                    }
                    );
                    break;
                }
            }
        }