Exemple #1
0
 static void TryDownloadUpdatePackage(string currVersion)
 {
     Task.Run(() =>
     {
         bool updateAvailable = false;
         try
         {
             if (KivaUpdates.GetLatestVersion() != currVersion)
             {
                 updateAvailable = true;
             }
         }
         catch { }
         if (updateAvailable)
         {
             UpdateDownloading = true;
             try
             {
                 var data = KivaUpdates.DownloadAssetData(KivaUpdates.DataAssetName);
                 var dest = File.OpenWrite(KivaUpdates.DefaultUpdatePackagePath);
                 data.CopyTo(dest);
                 data.Close();
                 dest.Close();
                 UpdateReady       = true;
                 UpdateDownloading = false;
             }
             catch (Exception e)
             {
                 MessageBox.Show("Couldn't download and save update package", "Update failed");
                 UpdateDownloading = false;
             }
         }
     });
 }
Exemple #2
0
        static void Main(string[] args)
        {
#if !DEBUG
            try
            {
#endif
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));

            MIDIPreRenderAudio.Init();

            var s = new KivaSettings();
            s.InitSoundfontListner();
            if (s.EnableUpdates)
            {
                if (File.Exists(KivaUpdates.DefaultUpdatePackagePath))
                {
                    try
                    {
                        using (var z = File.OpenRead(KivaUpdates.DefaultUpdatePackagePath))
                            using (ZipArchive archive = new ZipArchive(z))
                            { }
                        UpdateReady = true;
                        if (!KivaUpdates.IsAnotherKivaRunning())
                        {
                            if (args.Length == 0)
                            {
                                Process.Start(KivaUpdates.InstallerPath, "update -Reopen");
                            }
                            else
                            {
                                Process.Start(KivaUpdates.InstallerPath, "update -Reopen -ReopenArg \"" + args[0] + "\"");
                            }
                        }
                    }
                    catch (Exception e) { TryDownloadUpdatePackage(s.VersionName); }
                }
                else
                {
                    TryDownloadUpdatePackage(s.VersionName);
                }
            }

            var window = new MainWindow(s);
            if (args.Length != 0)
            {
                window.LoadMidi(args[0]);
            }
            window.ShowDialog();
#if !DEBUG
        }

        catch (Exception e)
        {
            string msg = e.Message + "\n" + e.Data + "\n";
            msg += e.StackTrace;
            MessageBox.Show(msg, "Kiva has crashed!");
        }
#endif
        }
Exemple #3
0
 public static void FinalizeInstall()
 {
     KivaUpdates.WriteVersionSettings(KivaUpdates.GetLatestVersion(), true, true);
     KivaUpdates.CopySelfInside(KivaUpdates.InstallerPath);
     KivaUpdates.CreateStartShortcut();
     KivaUpdates.CreateUninstallScript();
     KivaUpdates.CreateDesktopShortcut();
 }
Exemple #4
0
        static void SilentInstall()
        {
            var data = KivaUpdates.DownloadAssetData(KivaUpdates.DataAssetName);

            KivaUpdates.InstallFromStream(data);
            data.Close();
            FinalizeInstall();
        }
Exemple #5
0
        static void UpdateFromPackage(string path)
        {
            if (!File.Exists(path))
            {
                if (!Silent)
                {
                    MessageBox.Show("Could not install update, update package file missing", "Update failed");
                }
                return;
            }
            var f = File.OpenRead(path);

            KivaUpdates.KillAllKivas();
            KivaUpdates.InstallFromStream(f);
            f.Close();
            File.Delete(path);
        }
Exemple #6
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     Task.Run(() =>
     {
         try
         {
             var data = KivaUpdates.DownloadAssetData(KivaUpdates.DataAssetName);
             Dispatcher.Invoke(() => progressText.Content = "Installing...");
             KivaUpdates.InstallFromStream(data);
             data.Close();
             Program.FinalizeInstall();
             Dispatcher.Invoke(() => Close());
         }
         catch (Exception ex)
         {
             exception = ex;
             Dispatcher.Invoke(() => Close());
         }
     });
 }
Exemple #7
0
        static void Main(string[] args)
        {
            try
            {
                KivaUpdates.KillAllKivas();

                bool   reopen    = false;
                string reopenArg = "";

                if (args.Length == 0)
                {
                    reopen = true;
                    NormalInstall();
                }
                else
                {
                    string command = args[0];

                    if (!new[] { "install", "update", "uninstall" }.Contains(command))
                    {
                        Console.WriteLine("Invalid command " + command);
                        return;
                    }

                    string packagePath = KivaUpdates.DefaultUpdatePackagePath;

                    for (int i = 1; i < args.Length; i++)
                    {
                        if (args[i] == "-Silent")
                        {
                            Silent = true;
                        }
                        if (args[i] == "-PackagePath")
                        {
                            if (command != "update")
                            {
                                Console.WriteLine("-PackagePath flag only allowed on update command");
                                return;
                            }
                            i++;
                            if (i == args.Length)
                            {
                                Console.WriteLine("path expected after -PackagePath");
                                return;
                            }
                            packagePath = args[i];
                        }
                        if (args[i] == "-ReopenArg")
                        {
                            if (command == "uninstall")
                            {
                                Console.WriteLine("-ReopenArg flag not allowed on uninstall command");
                                return;
                            }
                            i++;
                            if (i == args.Length)
                            {
                                Console.WriteLine("argument expected after -ReopenArg");
                                return;
                            }
                            reopenArg = args[i];
                        }
                        if (args[i] == "-Reopen")
                        {
                            if (command == "uninstall")
                            {
                                Console.WriteLine("-Reopen flag not allowed on uninstall command");
                                return;
                            }
                            reopen = true;
                        }
                    }

                    if (command == "install")
                    {
                        if (Silent)
                        {
                            SilentInstall();
                        }
                        else
                        {
                            NormalInstall();
                        }
                    }
                    if (command == "update")
                    {
                        UpdateFromPackage(packagePath);
                        KivaUpdates.WriteVersionSettings(KivaUpdates.GetLatestVersion(), true, true);
                    }
                    if (command == "uninstall")
                    {
                        KivaUpdates.DeleteStartShortcut();
                        KivaUpdates.DeleteDesktopShortcut();
                        KivaUpdates.DeleteKivaFolder();
                        if (!Silent)
                        {
                            MessageBox.Show("Successfully uninstalled Kiva!");
                        }
                    }
                }

                if (reopen)
                {
                    string kivaPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Kiva/Kiva.exe");
                    if (reopenArg == "")
                    {
                        Process.Start(new ProcessStartInfo()
                        {
                            FileName         = kivaPath,
                            WorkingDirectory = Path.GetDirectoryName(kivaPath)
                        });
                    }
                    else
                    {
                        Process.Start(new ProcessStartInfo()
                        {
                            FileName         = kivaPath,
                            WorkingDirectory = Path.GetDirectoryName(kivaPath),
                            Arguments        = "\"" + reopenArg + "\""
                        });
                    }
                }
            }
            catch (Exception e)
            {
                if (!Silent)
                {
                    string msg = e.Message + "\n" + e.Data + "\n";
                    msg += e.StackTrace;
                    MessageBox.Show(msg, "Kiva installer has crashed!");
                }
            }
        }