예제 #1
0
파일: Program.cs 프로젝트: JFronny/UpTool2
        public static int Main(string[] args)
        {
            MutexLock.Lock();
            try
            {
                XmlTool.FixXml();
                ExternalFunctionalityManager.Init(Functions);
                RootCommand rootCommand = new RootCommand();

                PackageManagement.RegisterCommands(rootCommand);
                CacheManagement.RegisterCommands(rootCommand);
                ReposManagement.RegisterCommands(rootCommand);
                Other.RegisterCommands(rootCommand);

                return(rootCommand.InvokeAsync(args).Result);
            }
            catch (Exception e)
            {
                Console.WriteLine($"FAILED: {e}");
                return(1);
            }
            finally
            {
                MutexLock.Unlock();
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: JFronny/UpTool2
        private static void Install(bool noPrep)
        {
            WebClient client = new WebClient();

            Console.WriteLine("Downloading metadata");
            UpdateCheck.Reload("https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml");
            Console.WriteLine("Downloading binary");
            byte[] dl = client.DownloadData(UpdateCheck.App);
            Console.WriteLine("Verifying integrity");
            using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
            {
                string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty)
                                 .ToUpper();
                if (pkgHash != UpdateCheck.AppHash)
                {
                    throw new Exception($@"The hash is not equal to the one stored in the repo:
Package: {pkgHash}
Online: {UpdateCheck.AppHash}");
                }
            }
            Console.WriteLine("Extracting");
            if (Directory.Exists(PathTool.GetRelative("Install")))
            {
                foreach (string file in Directory.GetFiles(PathTool.GetRelative("Install")))
                {
                    File.Delete(file);
                }
                foreach (string dir in Directory.GetDirectories(PathTool.GetRelative("Install")))
                {
                    if (Path.GetFileName(dir) != "tmp")
                    {
                        Directory.Delete(dir, true);
                    }
                }
            }
            Directory.CreateDirectory(PathTool.GetRelative("Install"));
            using (MemoryStream ms = new MemoryStream(dl))
            {
                using ZipArchive ar = new ZipArchive(ms);
                ar.ExtractToDirectory(PathTool.GetRelative("Install"), true);
            }
            if (noPrep)
            {
                return;
            }
            Console.WriteLine("Preparing Repos");
            XmlTool.FixXml();
            RepoManagement.FetchRepos();
        }
예제 #3
0
 public static void FixXml(bool throwOnError = false)
 {
     try
     {
         XmlTool.FixXml();
     }
     catch (XmlException)
     {
         if (throwOnError)
         {
             throw;
         }
         MessageBox.Show("Something went wrong while trying to parse XML. Retrying...");
         File.Delete(PathTool.InfoXml);
         FixXml();
     }
 }
예제 #4
0
        private void install_Click(object sender, EventArgs e)
        {
            log.Visible = false;
            try
            {
                progress.Visible = true;
                WebClient client = new WebClient();
                Step(1, "Downloading metadata");
                XElement meta = XDocument.Load("https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml")
                                .Element("meta");
                Step(2, "Downloading binary");
                byte[] dl = client.DownloadData(meta.Element("File").Value);
                Step(3, "Verifying integrity");
                using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
                {
                    string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty).ToUpper();
                    if (pkgHash != meta.Element("Hash").Value.ToUpper())
                    {
                        throw new Exception(
                                  $@"The hash is not equal to the one stored in the repo:
Package: {pkgHash}
Online: {meta.Element("Hash").Value.ToUpper()}");
                    }
                }
                Step(4, "Extracting");
                if (Directory.Exists(PathTool.GetRelative("Install")))
                {
                    Directory.Delete(PathTool.GetRelative("Install"), true);
                }
                Directory.CreateDirectory(PathTool.GetRelative("Install"));
                using (MemoryStream ms = new MemoryStream(dl))
                {
                    using ZipArchive ar = new ZipArchive(ms);
                    ar.ExtractToDirectory(PathTool.GetRelative("Install"), true);
                }
                Step(5, "Creating shortcut");
                Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"),
                              System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs),
                                                     "UpTool2.lnk"));
                Step(6, "Preparing Repos");
                XmlTool.FixXml();
                RepoManagement.FetchRepos();
                if (pathBox.Checked)
                {
                    Step(7, startupBox.Checked ? "Creating PATH & Autostart entry" : "Creating PATH entry");
                    if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install"))))
                    {
                        Path.Append(PathTool.GetRelative("Install"));
                    }
                    if (startupBox.Checked)
                    {
                        _rkApp.SetValue(AppName, updateAppsBox.Checked ? "uptool dist-upgrade" : "uptool upgrade-self");
                    }
                    else if (_rkApp.GetValue(AppName) != null)
                    {
                        _rkApp.DeleteValue(AppName, false);
                    }
                }
                Step(8, "Done!");
            }
            catch (Exception ex)
            {
                Step(progress.Value, $"Failed!{Environment.NewLine}{ex}");
                BackColor         = Color.Red;
                processLabel.Text = "Failed";
                new Thread(() =>
                {
                    Thread.Sleep(1000);
                    Invoke(new Action(() =>
                    {
                        BackColor        = SystemColors.Control;
                        progress.Visible = false;
                    }));
                }).Start();
            }
            finally
            {
                log.Visible = true;
            }
        }