private void Check_Click(object sender, EventArgs e)
 {
     this.check.Enabled = false;
     using (this.updaterClient = new UpdaterClient())
     {
         this.updaterClient.UpdatesAvailable += this.UpdaterClientOnUpdatesAvailable;
         this.updaterClient.NoUpdatesAvailable += this._updaterClient_NoUpdatesAvailable;
         this.updaterClient.Notification += this._updaterClient_Notification;
         this.updaterClient.Updating += this._updaterClient_Updating;
         this.updaterClient.GetAvailableUpdates();
     }
     this.check.Enabled = true;
 }
Esempio n. 2
0
 private void Check_Click(object sender, EventArgs e)
 {
     this.check.Enabled = false;
     using (this.updaterClient = new UpdaterClient())
     {
         this.updaterClient.UpdatesAvailable   += this.UpdaterClientOnUpdatesAvailable;
         this.updaterClient.NoUpdatesAvailable += this._updaterClient_NoUpdatesAvailable;
         this.updaterClient.Notification       += this._updaterClient_Notification;
         this.updaterClient.Updating           += this._updaterClient_Updating;
         this.updaterClient.GetAvailableUpdates();
     }
     this.check.Enabled = true;
 }
Esempio n. 3
0
        private async Task UpdateProject(UpdaterClient updater, string projectRoot) {
            var targetPath = "";

            if (Program.IsUnix)
                targetPath = Path.Combine(Directory.GetParent(Assembly.GetEntryAssembly().Location).Parent.Parent.ToString(), projectRoot);  
            else
                targetPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), projectRoot);

            Application.Invoke((sender, args) => {
                PlayButton.Sensitive = false;
                PlayButton.Label = "Updating";
                ProgressBar.Text = "Checking for updates";
            });
            
            try {
                var cache = ChangeCache.FromFile(Path.Combine(targetPath, "version.json"));
                var version = await updater.FindLatestVersion();
                Console.WriteLine("Local version: {0}, Latest version: {1}", cache.Version, version);
                if (cache.Version >= version) {
                    Console.WriteLine("No updates available.");

                    Application.Invoke((sender, args)=> {
                        PlayButton.Sensitive = true;
                        PlayButton.Label = "Play";
                        ProgressBar.Text = "No updates available";
                    });
                    
                    return;
                }

                Application.Invoke((sender, args)=> {
                    ProgressBar.Text = "Getting version " + version + " from server...";
                    PlayButton.Sensitive = false;
                    PlayButton.Label = "Updating";
                });
                
                var changes = await updater.GetChanges(cache.Version, version);

                Application.Invoke((sender, args) =>
                {
                    ProgressBar.Text = "Preparing to update...";
                });               

                string progressFile = Path.Combine(targetPath, "updateProgress.json");

                if (!Directory.Exists(targetPath))
                    Directory.CreateDirectory(targetPath);

                string curProgress = "";

                if (File.Exists(progressFile))
                    curProgress = File.ReadAllText(progressFile);

                if (curProgress == "")
                    curProgress = "{}";

                UpdateProgress progress = JsonConvert.DeserializeObject<UpdateProgress>(curProgress);

                if (progress == null) {
                    progress = new UpdateProgress();
                    progress.setVersion(version);
                }

                if (progress.Downloaded == 0)
                    progress.setVersion(version);

                if (progress.TargetVersion != version) {
                    UpdateLib.Version oldV = progress.TargetVersion;
                    Application.Invoke((sender, args) => {
                        var dialog = new MessageDialog(Window, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok,
                            false, "Your previous download progress was for v{0}, but the target version is v{1}. As a result, your download progress was reset.",
                            oldV, version) { Title = "Progress Version Mismatch" };

                        dialog.Run();
                        dialog.Destroy();
                    });

                    progress.setVersion(version);
                    progress.DownloadedFiles = new List<string>();
                }
                    
                List<KeyValuePair<string, int>> changesLeft = changes.NewSizes.Where(c => !progress.DownloadedFiles.Contains(c.Key)).ToList();

                var totalSize = ByteSize.FromBytes(changesLeft.Sum(kvp => kvp.Value));
                long currentDownloaded = 0;
                foreach (var change in changesLeft) {
                    var relativePath = change.Key;

                    if(Program.IsUnix)
                        relativePath = relativePath.Replace('\\','/');

                    var targetFile = Path.Combine(targetPath, relativePath);

                    if (File.Exists(targetFile))
                        File.Delete(targetFile);

                    await updater.Download(relativePath, targetFile, version);

                    currentDownloaded += change.Value;

                    Application.Invoke((_, args) => {
                        UpdateDownloadProgress(relativePath, ByteSize.FromBytes(currentDownloaded), totalSize);
                    });

                    progress.DownloadedFiles.Add(change.Key);
                    File.WriteAllText(progressFile, JsonConvert.SerializeObject(progress));
                }
                cache.SetVersion(version);

                if (File.Exists(progressFile))
                    File.Delete(progressFile);

                Application.Invoke((sender, args) => {
                    PlayButton.Sensitive = true;
                    PlayButton.Label = "Play";
                    ProgressBar.Text = "Finished Updating";
                });

                if (Program.IsUnix) {
                    // Update fix for Mac
                    string executeScript = "";

                    if (updater.GetProjectName() == _setup.LauncherProject)
                        executeScript = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "atmolauncher");
                    else if (updater.GetProjectName() == _setup.GameProject)
                        executeScript = Path.Combine(targetPath, _setup.GameExecutable, "Contents", "MacOS", "Atmosphir");

                    Program.macChangePerm(executeScript);
                }

                if (updater.GetProjectName() == _setup.LauncherProject)
                    Program.RebootOrig();
            }
            catch (Exception e) {
                if (e is System.Net.WebException || e is System.Net.Http.HttpRequestException || e is System.Net.Sockets.SocketException) {
                    Application.Invoke((sender, args) => {
                        PlayButton.Sensitive = true;
                        PlayButton.Label = "Play";
                        ProgressBar.Text = "Couldn't connect to update server.";
                    });
                }
                else {
                    Application.Invoke((sender, args) => {
                        Console.WriteLine(e);
                        var dialog = new MessageDialog(Window, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
                                                        false, e.GetType() + "An error ocurred, please report this at {0}:\n{1}", _setup.SupportSite, e)
                        {
                            Title = "Update error"
                        };
                        dialog.Run();
                        dialog.Destroy();
                    });
                }
            }
        }
Esempio n. 4
0
        private async Task UpdateProject(UpdaterClient updater, string projectRoot)
        {
            var targetPath = "";

            if (Program.IsUnix)
            {
                targetPath = Path.Combine(Directory.GetParent(Assembly.GetEntryAssembly().Location).Parent.Parent.ToString(), projectRoot);
            }
            else
            {
                targetPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), projectRoot);
            }

            Application.Invoke((sender, args) => {
                PlayButton.Sensitive = false;
                PlayButton.Label     = "Updating";
                ProgressBar.Text     = "Checking for updates";
            });

            try {
                var cache   = ChangeCache.FromFile(Path.Combine(targetPath, "version.json"));
                var version = await updater.FindLatestVersion();

                Console.WriteLine("Local version: {0}, Latest version: {1}", cache.Version, version);
                if (cache.Version >= version)
                {
                    Console.WriteLine("No updates available.");

                    Application.Invoke((sender, args) => {
                        PlayButton.Sensitive = true;
                        PlayButton.Label     = "Play";
                        ProgressBar.Text     = "No updates available";
                    });

                    return;
                }

                Application.Invoke((sender, args) => {
                    ProgressBar.Text     = "Getting version " + version + " from server...";
                    PlayButton.Sensitive = false;
                    PlayButton.Label     = "Updating";
                });

                var changes = await updater.GetChanges(cache.Version, version);

                Application.Invoke((sender, args) =>
                {
                    ProgressBar.Text = "Preparing to update...";
                });

                string progressFile = Path.Combine(targetPath, "updateProgress.json");

                if (!Directory.Exists(targetPath))
                {
                    Directory.CreateDirectory(targetPath);
                }

                string curProgress = "";

                if (File.Exists(progressFile))
                {
                    curProgress = File.ReadAllText(progressFile);
                }

                if (curProgress == "")
                {
                    curProgress = "{}";
                }

                UpdateProgress progress = JsonConvert.DeserializeObject <UpdateProgress>(curProgress);

                if (progress == null)
                {
                    progress = new UpdateProgress();
                    progress.setVersion(version);
                }

                if (progress.Downloaded == 0)
                {
                    progress.setVersion(version);
                }

                if (progress.TargetVersion != version)
                {
                    UpdateLib.Version oldV = progress.TargetVersion;
                    Application.Invoke((sender, args) => {
                        var dialog = new MessageDialog(Window, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok,
                                                       false, "Your previous download progress was for v{0}, but the target version is v{1}. As a result, your download progress was reset.",
                                                       oldV, version)
                        {
                            Title = "Progress Version Mismatch"
                        };

                        dialog.Run();
                        dialog.Destroy();
                    });

                    progress.setVersion(version);
                    progress.DownloadedFiles = new List <string>();
                }

                List <KeyValuePair <string, int> > changesLeft = changes.NewSizes.Where(c => !progress.DownloadedFiles.Contains(c.Key)).ToList();

                var  totalSize         = ByteSize.FromBytes(changesLeft.Sum(kvp => kvp.Value));
                long currentDownloaded = 0;
                foreach (var change in changesLeft)
                {
                    var relativePath = change.Key;

                    if (Program.IsUnix)
                    {
                        relativePath = relativePath.Replace('\\', '/');
                    }

                    var targetFile = Path.Combine(targetPath, relativePath);

                    if (File.Exists(targetFile))
                    {
                        File.Delete(targetFile);
                    }

                    await updater.Download(relativePath, targetFile, version);

                    currentDownloaded += change.Value;

                    Application.Invoke((_, args) => {
                        UpdateDownloadProgress(relativePath, ByteSize.FromBytes(currentDownloaded), totalSize);
                    });

                    progress.DownloadedFiles.Add(change.Key);
                    File.WriteAllText(progressFile, JsonConvert.SerializeObject(progress));
                }
                cache.SetVersion(version);

                if (File.Exists(progressFile))
                {
                    File.Delete(progressFile);
                }

                Application.Invoke((sender, args) => {
                    PlayButton.Sensitive = true;
                    PlayButton.Label     = "Play";
                    ProgressBar.Text     = "Finished Updating";
                });

                if (Program.IsUnix)
                {
                    // Update fix for Mac
                    string executeScript = "";

                    if (updater.GetProjectName() == _setup.LauncherProject)
                    {
                        executeScript = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "atmolauncher");
                    }
                    else if (updater.GetProjectName() == _setup.GameProject)
                    {
                        executeScript = Path.Combine(targetPath, "Contents", "MacOS", "Atmosphir");
                    }

                    Program.macChangePerm(executeScript);
                }

                if (updater.GetProjectName() == _setup.LauncherProject)
                {
                    Program.RebootOrig();
                }
            }
            catch (Exception e) {
                if (e is System.Net.WebException || e is System.Net.Http.HttpRequestException || e is System.Net.Sockets.SocketException)
                {
                    Application.Invoke((sender, args) => {
                        PlayButton.Sensitive = true;
                        PlayButton.Label     = "Play";
                        ProgressBar.Text     = "Couldn't connect to update server.";
                    });
                }
                else
                {
                    Application.Invoke((sender, args) => {
                        Console.WriteLine(e);
                        var dialog = new MessageDialog(Window, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok,
                                                       false, e.GetType() + "An error ocurred, please report this at {0}:\n{1}", _setup.SupportSite, e)
                        {
                            Title = "Update error"
                        };
                        dialog.Run();
                        dialog.Destroy();
                    });
                }
            }
        }
Esempio n. 5
0
        private async Task UpdateProject(UpdaterClient updater, string projectRoot)
        {
            var targetPath = "";

            if (Program.IsUnix)
            {
                targetPath = Path.Combine(Directory.GetParent(Assembly.GetEntryAssembly().Location).Parent.Parent.ToString(), projectRoot);
            }
            else
            {
                targetPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), projectRoot);
            }

            Console.WriteLine("Checking for updates...");

            try
            {
                var cache   = ChangeCache.FromFile(Path.Combine(targetPath, "version.json"));
                var version = await updater.FindLatestVersion();

                Console.WriteLine("Local version: {0}, Latest version: {1}", cache.Version, version);
                if (cache.Version >= version)
                {
                    Console.WriteLine("No updates available.");
                    return;
                }

                Console.WriteLine("Getting version v{0} from the server...", version);

                var changes = await updater.GetChanges(cache.Version, version);

                Console.WriteLine("Preparing to update...");

                string progressFile = Path.Combine(targetPath, "updateProgress.json");

                if (!Directory.Exists(targetPath))
                {
                    Directory.CreateDirectory(targetPath);
                }

                string curProgress = "";

                if (File.Exists(progressFile))
                {
                    curProgress = File.ReadAllText(progressFile);
                }

                if (curProgress == "")
                {
                    curProgress = "{}";
                }

                UpdateProgress progress = JsonConvert.DeserializeObject <UpdateProgress>(curProgress);

                if (progress == null)
                {
                    progress = new UpdateProgress();
                    progress.setVersion(version);
                }

                if (progress.Downloaded == 0)
                {
                    progress.setVersion(version);
                }

                if (progress.TargetVersion != version)
                {
                    UpdateLib.Version oldV = progress.TargetVersion;
                    Console.WriteLine("NOTICE: Your previous download progress was for v{0}, but the target version is v{1}. As a result, your download progress was reset.", oldV, version);

                    progress.setVersion(version);
                    progress.DownloadedFiles = new List <string>();
                }

                List <KeyValuePair <string, int> > changesLeft = changes.NewSizes.Where(c => !progress.DownloadedFiles.Contains(c.Key)).ToList();

                var  totalSize         = ByteSize.FromBytes(changesLeft.Sum(kvp => kvp.Value));
                long currentDownloaded = 0;
                foreach (var change in changesLeft)
                {
                    var relativePath = change.Key;

                    if (Program.IsUnix)
                    {
                        relativePath = relativePath.Replace('\\', '/');
                    }

                    var targetFile = Path.Combine(targetPath, relativePath);

                    if (File.Exists(targetFile))
                    {
                        File.Delete(targetFile);
                    }

                    await updater.Download(relativePath, targetFile, version);

                    currentDownloaded += change.Value;

                    UpdateDownloadProgress(relativePath, ByteSize.FromBytes(currentDownloaded), totalSize);

                    progress.DownloadedFiles.Add(change.Key);
                    File.WriteAllText(progressFile, JsonConvert.SerializeObject(progress));
                }
                cache.SetVersion(version);

                if (File.Exists(progressFile))
                {
                    File.Delete(progressFile);
                }

                Console.WriteLine("Finished Updating!");

                if (Program.IsUnix)
                {
                    // Update fix for Mac
                    string executeScript = "";

                    if (updater.GetProjectName() == _setup.LauncherProject)
                    {
                        executeScript = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "atmolauncher");
                    }
                    else if (updater.GetProjectName() == _setup.GameProject)
                    {
                        executeScript = Path.Combine(targetPath, _setup.GameExecutable, "Contents", "MacOS", "Atmosphir");
                    }

                    Program.macChangePerm(executeScript);
                }

                if (updater.GetProjectName() == _setup.LauncherProject)
                {
                    Program.RebootOrig();
                }
            }
            catch (Exception e)
            {
                if (e is System.Net.WebException || e is System.Net.Http.HttpRequestException || e is System.Net.Sockets.SocketException)
                {
                    Console.WriteLine("ERROR: Couldn't connect to update server. Please check your internet connection or try again later.");
                    errorOcurred = true;
                }
                else
                {
                    Console.WriteLine("An error ocurred, please report this at {0}:\n{1}", _setup.SupportSite, e);
                    errorOcurred = true;
                }
            }
        }
 public void LoadConfiguration(object sender, EventArgs e)
 {
     using (this.updaterClient = new UpdaterClient())
         this.updaterClient.GetAvailableUpdates();
 }
Esempio n. 7
0
        private void DownloadFromServer()
        {
            try
            {
                DrawProgresBarDelegate handler = DrawProgresBar;
                Invoke(handler, new object[] { true });
                //Show2ButtonDelegate handler0 = Disable1Button;
                //Invoke(handler0, new object[] {});

                DirectoryInfo source = new DirectoryInfo(SourceDir);

                if (!source.Exists)
                {
                    source.Create();
                }

                string          remoteAddress = Url;
                EndpointAddress endpoint      = new EndpointAddress(remoteAddress);


                BasicHttpBinding binding = new BasicHttpBinding();
                binding.MaxReceivedMessageSize = Int32.MaxValue; // 658752;//458752;// Int32.MaxValue; //104857600;
                var update     = new UpdaterClient(binding, endpoint);
                var names      = update.GetHeshes();
                var localFiles = GetLocalFilesWithHeshes();
                // var filesDevice = Directory.GetFiles(SourceDir);

                for (int i = 0; i < names.Length; i++)
                {
                    var s = names[i].Key;
                    if (s != null)
                    {
                        int pos = s.LastIndexOf(@"\") + 1;
                        var s1  = s.Substring(pos, s.Length - pos);

                        DrawDelegate handler2 = Draw;
                        Invoke(handler2, new object[] { s1, i, names.Length });
                        if (!SearchFileInLocalDir(s1, names[i].Value, localFiles))    // filesDevice))
                        {
                            //Draw(s1, i, names.Length);
                            var a0 = update.DownloadFile(s);
                            if (s1 == StartFileLink)
                            {
                                WriteFile(StartUpDir + "\\" + s1, a0);
                                WriteFile(ProgramsDir + "\\" + s1, a0);
                            }
                            else
                            {
                                WriteFile(SourceDir + "\\" + s1, a0);
                            }
                        }
                    }
                }
                DrawProgresBarDelegate handler3 = DrawProgresBar;
                Invoke(handler3, new object[] { false });

                Show2ButtonDelegate handler4 = Show2Button;
                Invoke(handler4, new object[] {});
                // button2.Visible = true;
                //MessageBox.Show("That's all, folks");
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format
                                    ("Connection Error: {0}", ex.Message));
                DrawProgresBarDelegate handler8 = DrawProgresBar;
                Invoke(handler8, new object[] { false });

                Show2ButtonDelegate handler9 = Enable1Button;
                Invoke(handler9, new object[] {});

                // progressBar1.Visible = false;
            }
        }
Esempio n. 8
0
 public void LoadConfiguration(object sender, EventArgs e)
 {
     using (this.updaterClient = new UpdaterClient())
         this.updaterClient.GetAvailableUpdates();
 }