private void Unpack()
 {
     try
     {
         StatusText.Text = "Starting unpacker...";
         StatusText.Text = "Unpacking...";
         DFUnpack      dfu = StaticMemory.DFU;
         DirectoryInfo dir = Directory.CreateDirectory(TempController.GeneratedDir.FullName + "/update");
         ZipFile.ExtractToDirectory(TempController.GeneratedDir.FullName + "/" + dfu.Filename, dir.FullName);
         StatusText.Text = "Deleting old version...";
         if (Directory.Exists(dfu.InstallPath))
         {
             TempController.DestroyDirectory(dfu.InstallPath);
             Directory.Delete(dfu.InstallPath);
         }
         StatusText.Text = "Moving files...";
         Directory.Move(dir.FullName, dfu.InstallPath);
         StatusText.Text = "Finalizing update...";
         Application.Current.Shutdown(ExitCode.Success);
     } catch (Exception e)
     {
         Debug.WriteLine("Exception: " + e.Message);
         Application.Current.Shutdown(ExitCode.InternalError);
         return;
     }
 }
Exemplo n.º 2
0
 protected override void OnStartup(StartupEventArgs e)
 {
     try
     {
         MainWindow mw = new MainWindow();
         base.OnStartup(e);
         if (e.Args.Length == 2)
         {
             if (e.Args[0] == "test")
             {
                 Debug.Listeners.Add(new TextWriterTraceListener(TempController.GenTempDir().FullName + "/debug.log"));
                 StaticMemory.Operation = Operation.Test;
                 StaticMemory.Args      = e.Args;
                 Debug.WriteLine("Using DFTestXml: " + e.Args[1]);
                 new MainTest();
             }
             else if (e.Args[0] == "install")
             {
                 Debug.Listeners.Add(new TextWriterTraceListener(TempController.GenTempDir().FullName + "/debug.log"));
                 StaticMemory.Operation = Operation.Test;
                 StaticMemory.Operation = Operation.Install;
                 StaticMemory.Args      = e.Args;
                 Debug.WriteLine("Using DFInstallXml: " + e.Args[1]);
                 mw.Show();
             }
             else if (e.Args[0] == "finalize")
             {
                 TempController.GenTempDir(int.Parse(e.Args[1]));
                 TempController.ClearDirectory();
             }
             else if (e.Args[0] == "unpack")
             {
                 StaticMemory.Operation = Operation.Unpack;
                 StaticMemory.Args      = e.Args;
                 StaticMemory.DFU       = DFUnpack.ParseXml(e.Args[1]);
                 Debug.Listeners.Add(new TextWriterTraceListener(TempController.GenTempDir(StaticMemory.DFU.InstallId).FullName + "/debug-installer.log"));
                 Debug.WriteLine("Using DFUnpackXml: " + e.Args[1]);
                 Debug.WriteLine("Temp path: " + TempController.GeneratedDir.FullName);
                 mw.Show();
             }
             else
             {
                 Current.Shutdown(ExitCode.UnknownArgs);
             }
         }
         else
         {
             Current.Shutdown(ExitCode.UnknownArgs);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception: " + ex.Message);
         Current.Shutdown(ExitCode.InternalError);
         return;
     }
 }
 private async void Download()
 {
     try
     {
         StatusText.Text = "Starting downloader...";
         DFInstall dfi = DFInstall.ParseXml(StaticMemory.Args[1]);
         if (dfi == null)
         {
             return;
         }
         Core.Xml.DarkFrontier darkfile = Core.ServerRequest.GetDarkFrontier(dfi.ServerUrl);
         if (darkfile == null)
         {
             return;
         }
         dl = new Downloader(StatusText, dfi.ProductName);
         await(StaticMemory.DownloadFile = dl.DownloadFile(darkfile.Filename, darkfile.DownloadUrl));
         if (StaticMemory.Errored)
         {
             return;
         }
         StatusText.Text = "Copying the DarkFrontier";
         File.Copy(Assembly.GetExecutingAssembly().Location, TempController.GeneratedDir.FullName + "/update.exe");
         StatusText.Text = "Executing DarkFrontier";
         MainWindow.Instance.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;
         Process  proc = new Process();
         DFUnpack dfu  = new DFUnpack(TempController.InstallId, darkfile.Filename, dfi.InstallPath, darkfile.DFPath);
         proc.StartInfo.Arguments = "unpack \"" + DFUnpack.ToString(dfu) + "\"";
         Debug.WriteLine("Using unpack: " + DFUnpack.ToString(dfu));
         proc.StartInfo.UseShellExecute = true;
         proc.StartInfo.FileName        = TempController.GeneratedDir.FullName + "/update.exe";
         Debug.WriteLine("Executable in " + TempController.GeneratedDir.FullName + "/update.exe");
         proc.StartInfo.Verb = "runas";
         Notify.Dispose();
         Debug.WriteLine("Process started? " + (proc.Start() ? "yes" : "no"));
         Application.Current.Shutdown(ExitCode.Unpacking);
     }
     catch (Exception e)
     {
         Debug.WriteLine("Exception: " + e.Message);
         Application.Current.Shutdown(ExitCode.InternalError);
         return;
     }
 }