Example #1
0
        public static void Update(string installedVersion)
        {
            var currentVersion = GetCurrentVersion();

            if (!NewerVersion(installedVersion, currentVersion))
            {
                return;
            }
            var success = false;

            do
            {
                Console.WriteLine("There is a newer version of Yellow Pointer available\nWould you like to download it? (Y/N)");
                var result = Console.ReadLine();
                if (result == null)
                {
                    Console.WriteLine("Invalid response");
                    continue;
                }
                result = result.ToLower();
                switch (result)
                {
                case "n":
                    success = true;
                    break;

                case "y":
                    Console.WriteLine("Downloading file...");
                    var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    desktop += Utility.DetermineOs() == "windows" ? '\\' : '/';
                    using (var wd = new Utility.WebDownload())
                    {
                        wd.DownloadProgressChanged += OnDownloadProgressChanged;

                        wd.DownloadFile(UpdateLink, desktop + "Yellow_Pointer.zip");
                    }
                    //Unzip file
                    Directory.CreateDirectory(desktop + "Yellow_Pointer");
                    ZipFile.ExtractToDirectory(desktop + "Yellow_Pointer.zip", desktop + "Yellow_Pointer");
                    //Delete zip
                    File.Delete(desktop + "Yellow_Pointer.zip");
                    //Run installer
                    if (Utility.DetermineOs() == "macos")
                    {
                        var command = @"mono " + desktop + @"Yellow_Pointer/Yellow\ Pointer\ Installer.exe";
                        Utility.ExecuteCommand(command);
                    }
                    else
                    {
                        Process.Start(desktop + "Yellow_Pointer/Yellow Pointer Installer.exe");
                    }
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Invalid response");
                    break;
                }
            } while (!success);
        }
        private static bool DownloadFormsIndex()
        {
            Console.WriteLine("Checking for updates, please wait...");
            bool success;
            var  attempt = 1;

            do
            {
                //Download file
                using (var wd = new Utility.WebDownload())
                {
                    try
                    {
                        wd.DownloadFile(SecFormAddress, Temp + "form.gz");
                    }
                    catch (Exception)
                    {
                        if (attempt > 3)
                        {
                            Console.WriteLine("Could not download index. Please try again later.");
                            Console.WriteLine("Press any key to continue...");
                            Console.ReadKey();
                            return(false);
                        }
                        Console.WriteLine("Attempt " + attempt + " of 3 failed...");
                        attempt++;
                    }
                }
                success = true;
            } while (!success);

            //Decompress form.gz
            var file = new FileInfo(Temp + "form.gz");

            using (var originalFileStream = file.OpenRead())
            {
                var currentFileName = file.FullName;
                var newFileName     = currentFileName.Remove(currentFileName.Length - file.Extension.Length);

                using (var decompressedFileStream = File.Create(newFileName + ".idx"))
                {
                    using (var decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
                    {
                        decompressionStream.CopyTo(decompressedFileStream);
                    }
                }
            }
            return(true);
        }
Example #3
0
        public List <Index> GetIndexListing()
        {
            List <Index> list = null;

            try
            {
                using (var webClient = new Utility.WebDownload())
                {
                    webClient.DownloadFile("https://s3.amazonaws.com/" + BackupBucket + "/index.json",
                                           _temp + "index.json");
                }
                list =
                    JsonConvert.DeserializeObject <List <Index> >(File.ReadAllText(_temp + "index.json")) ??
                    new List <Index>();
                File.Delete(_temp + "index.json");
            }
            catch (Exception)
            {
                // ignored
            }
            return(list);
        }