Ejemplo n.º 1
0
        public static bool start(string[] args)
        {
            string full_path_here;

            if (File.Exists(full_path_here = constants.path_here + SerializableUpdateInfo.filename))
            {
                current = SerializableUpdateInfo.Deserialize <SerializableUpdateInfo>(constants.path_here);
            }
            string full_path_updated;

            if (File.Exists(full_path_updated = constants.path_updated + SerializableUpdateInfo.filename))
            {
                available_local = SerializableUpdateInfo.Deserialize <SerializableUpdateInfo>(constants.path_updated);
            }
#if DEBUG
            Console.WriteLine("from Updater.Program.start: ");
            Console.WriteLine("+_full_path_here: " + full_path_here);
            Console.WriteLine("+_full_path_updated: " + full_path_updated);
#endif
            //Check for available online
            available_online = GetUpdates();

            switch (current | available_local)
            {
            case SerializableUpdateInfo.update_action.keep_old:
                Console.WriteLine("Keep old");
                return(false);

            case SerializableUpdateInfo.update_action.update_new:
                Console.WriteLine("Update new");
                OpenInstaller();
                Thread.Sleep(int.MaxValue);
                return(true);
            }

            //OPEN INSTALLER IF NECESSARY
            //BE SURE TO CLOSE THE PROGRAM IF OPEN INSTALLER
            //System.Environment.Exit(0);
#if try__
            OpenInstaller();
            //Thread.Sleep(int.MaxValue);
#endif

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// OVERRIDE; Get the zip from github, extract, and delete the zip
        /// </summary>
        public static SerializableUpdateInfo GetUpdates()
        {
            using (var client = new WebClient())
            {
                if (!File.Exists(constants.path_updated))
                {
                    Directory.CreateDirectory(constants.path_updated);
                }
                string updated_zip;
#if TRACE
                Console.WriteLine("Downloading update zip");
#endif
                client.DownloadFile(built_zip_file_updated, updated_zip = constants.path_updated + "built_pegasus.zip");
#if TRACE
                Console.WriteLine("Download complete, files stored in " + updated_zip);
#endif
                string extracted = Path.Join(constants.path_updated, "extracted");
                Directory.CreateDirectory(extracted);
#if TRACE
                Console.WriteLine("Seeing inside folder " + extracted + " to find any sub-directories");
#endif
                string[] files_in_extracted = Directory.GetDirectories(extracted);

                if (files_in_extracted.Length > 0)
                {
#if TRACE
                    Console.WriteLine("There is at least one file inside " + extracted);
#endif
                    foreach (string file in files_in_extracted)
                    {
#if TRACE
                        Console.WriteLine("Deleting " + file);
#endif
                        Directory.Delete(file, true);
#if TRACE
                        Console.WriteLine("Deletion successful.");
#endif
                    }
                }
#if TRACE
                Console.WriteLine("Unzipping " + updated_zip);
#endif
                System.IO.Compression.ZipFile.ExtractToDirectory(updated_zip, extracted);
#if TRACE
                Console.WriteLine("Unzip complete, deleting " + updated_zip);
                Console.WriteLine("Bad algorithm started");
#endif
                string new_root = extracted;
#if TRACE
                Console.WriteLine("From new_root: " + new_root);
#endif
                if (check_for_version(new_root, out new_root))
                {
#if TRACE
                    Console.WriteLine("Found version at " + new_root);
#endif
                    return(SerializableUpdateInfo.Deserialize <SerializableUpdateInfo>(new_root));
                }
                else
                {
#if TRACE
                    Console.WriteLine("No version is found");
#endif
                    return(null);
                }
            }
        }