示例#1
0
        public void DoUpdate()
        {
            AddonRemote = new AptRemote(AddonEnv);

            Output.Info("Action: update repository database.");
            PrintEnvInfo();
            try
            {
                if (AddonRepo == null)
                {
                    AddonRepo = new AptRepository(AddonEnv);
                }
                Output.Info(String.Format("Current index from: {0}", AddonRepo.GetRepositoryDate()));
                Output.Info(String.Format("There are currently {0} addons in the database.", AddonRepo.GetAddonNum()));
            }
            catch (Exception e)
            {
                Output.Error("Failed to load current index file.");
            }

            Output.Info("Downloading index file...");

            if (AddonRemote.UpdateIndexFile())
            {
                Output.Info("Download successful.");

                try
                {
                    AddonRepo = new AptRepository(AddonEnv);
                    Output.Info(String.Format("Updated index from: {0}", AddonRepo.GetRepositoryDate()));
                    Output.Info(String.Format("There are now {0} addons in the database.", AddonRepo.GetAddonNum()));
                }
                catch (Exception e)
                {
                    Output.Error("Failed to downloaded index file.");
                }
            }
            else
            {
                Output.Error("Download failed.");
            }
        }
示例#2
0
        public void DoInstall()
        {
            AddonLocal  = new AptLocal(AddonEnv);
            AddonRemote = new AptRemote(AddonEnv);

            if (Cfg.AutoUpdateIndex)
            {
                DoUpdate();
            }

            Output.Info("Action: install addon(s).");

            int installedAddons = 0;

            if (InitializeRepository())
            {
                if (!Cfg.AutoUpdateIndex)
                {
                    Output.Info(String.Format("There are currently {0} addons in the database.", AddonRepo.GetAddonNum()));
                    PrintEnvInfo();
                }

                AptActionInstall install = new AptActionInstall(AddonEnv, AddonLocal, AddonRemote, AddonRepo);
                install.AddStatusListener(new AptAction.StatusMessageEventHandler(InstallStatusMessage));

                foreach (string addon in ArgAddons)
                {
                    if (AddonRepo.IsAddonInRepository(addon))
                    {
                        if (install.Install(addon, false))
                        {
                            installedAddons++;
                        }
                    }
                    else
                    {
                        Output.Error(String.Format("Addon not found: {0}", addon));
                    }
                }

                Output.Info(String.Format("Addons installed: {0}", installedAddons));
            }
        }
示例#3
0
        public void DoUpgrade()
        {
            AddonLocal  = new AptLocal(AddonEnv);
            AddonRemote = new AptRemote(AddonEnv);

            if (Cfg.AutoUpdateIndex)
            {
                DoUpdate();
            }

            if (InitializeRepository())
            {
                if (!Cfg.AutoUpdateIndex)
                {
                    Output.Info(String.Format("There are currently {0} addons in the database.", AddonRepo.GetAddonNum()));
                    PrintEnvInfo();
                }

                int updatedAddons;

                AptActionUpgrade upgrade = new AptActionUpgrade(AddonEnv, AddonLocal, AddonRemote, AddonRepo);
                upgrade.AddStatusListener(new AptAction.StatusMessageEventHandler(UpgradeStatusMessage));

                foreach (string excludeAddon in ArgExclude)
                {
                    upgrade.Exclude(excludeAddon);
                }

                if (ArgAddons.Count == 0)
                {
                    Output.Info("Action: upgrade all addons.");
                    updatedAddons = upgrade.Prepare();
                }
                else
                {
                    Output.Info("Action: upgrade some addons.");

                    for (int i = 0; i < ArgAddons.Count; ++i)
                    {
                        upgrade.AddPattern(ArgAddons[i]);
                    }
                    updatedAddons = upgrade.Prepare();
                }

                if (updatedAddons > 0)
                {
                    Output.Info("An update is available for the following addons");

                    List <string> updated = upgrade.GetQueue();

                    // calculate download size
                    int downloadSize = 0;
                    foreach (string addon in updated)
                    {
                        downloadSize += AddonRepo.GetAddonInfo(addon).ZipFileSize;
                    }

                    Output.Append(String.Format(" (approx. {0} KB to download):\n\n", (downloadSize / 1024)));

                    Output.Append("  " + String.Join(", ", updated.ToArray()));

                    if (!Cfg.SilentMode)
                    {
                        Output.Append("\n\nDo you want to proceed? [Y/N]: ");

                        if (Convert.ToChar(Console.Read()).ToString().ToLower() == "y")
                        {
                            upgrade.Run();
                        }
                    }
                    else
                    {
                        upgrade.Run();
                    }
                }
                else
                {
                    Output.Info("No updates available.");
                }
            }
        }