示例#1
0
        /// <summary>
        /// Swaps the start building of the craft.
        /// </summary>
        public static void SwapBuildingOfSelectedCraft(CraftNode craftNode)
        {
            string fullPath = KSPPathHelper.GetAbsolutePath(craftNode.FilePath);

            if (File.Exists(fullPath))
            {
                string newType = GetOtherBuilding(craftNode.Type);
                string newPath = GetNewPath(craftNode, newType);
                string allText = File.ReadAllText(fullPath);
                if (!ChangeParameter(ref allText, craftNode.Name, "type", craftNode.Type, newType))
                {
                    return;
                }

                File.WriteAllText(fullPath, allText);
                File.Move(fullPath, newPath);

                Messenger.AddInfo(string.Format(Messages.MSG_BUILDING_OF_CRAFT_0_SWAPPED_1_2, craftNode.Name, craftNode.Type, newType));

                craftNode.Type     = newType;
                craftNode.FilePath = newPath;

                View.InvalidateView();
            }
        }
        private void ReadKSPSettings()
        {
            string path = Path.Combine(KSPPathHelper.GetPath(KSPPaths.KSPRoot), PARAM_SETTINGS_CFG);

            if (File.Exists(path))
            {
                string fileContent = File.ReadAllText(path);
                int    index1      = fileContent.IndexOf(Constants.SCREEN_WIDTH) + Constants.SCREEN_WIDTH.Length;
                int    index2      = fileContent.IndexOf(Environment.NewLine, index1);
                string width       = fileContent.Substring(index1, index2 - index1).Replace(EQUALS, string.Empty).Trim();
                index1 = fileContent.IndexOf(Constants.SCREEN_HEIGHT) + Constants.SCREEN_HEIGHT.Length;
                index2 = fileContent.IndexOf(Environment.NewLine, index1);
                string height = fileContent.Substring(index1, index2 - index1).Replace(EQUALS, string.Empty).Trim();
                ScreenResolution = string.Format(PARAM_0_X_1, width, height);
                index1           = fileContent.IndexOf(Constants.FULLSCREEN) + Constants.FULLSCREEN.Length;
                index2           = fileContent.IndexOf(Environment.NewLine, index1);
                Fullscreen       = fileContent.Substring(index1, index2 - index1).Replace(EQUALS, string.Empty).Trim().ToLower() == TRUE;

                settingsFileFound = true;
            }
            else
            {
                Messenger.AddInfo(Messages.MSG_CANT_FIND_KSP_SETTINGS);
                settingsFileFound = false;
            }
        }
示例#3
0
        /// <summary>
        /// Loads the AppConfig and KSPConfig.
        /// </summary>
        protected static void LoadConfigs()
        {
            Messenger.AddInfo(Messages.MSG_LOADING_KSPMA_SETTINGS);
            string path = KSPPathHelper.GetPath(KSPPaths.AppConfig);

            if (File.Exists(path))
            {
                if (AdminConfig.Load(path))
                {
                    Messenger.AddInfo(Messages.MSG_DONE);

                    // LoadKSPConfig will be started by KSPPathChange event.
                    ////if (KSPPathHelper.IsKSPInstallFolder(OptionsController.SelectedKSPPath))
                    ////    LoadKSPConfig();
                }
                else
                {
                    Messenger.AddInfo(Messages.MSG_LOADING_KSPMA_SETTINGS_FAILED);
                }
            }
            else
            {
                Messenger.AddInfo(Messages.MSG_KSPMA_SETTINGS_NOT_FOUND);
            }

            DeleteOldAppConfigs();
        }
        private static void CreateNeededDirectories()
        {
            string path = KSPPathHelper.GetPath(KSPPaths.GameData);

            if (path == string.Empty)
            {
                Messenger.AddInfo("Invalid KSP path.");
                return;
            }

            // Create .../GameData if not exist.
            if (!Directory.Exists(path))
            {
                Messenger.AddInfo(string.Format(Messages.MSG_CREATING_DIR_0, path));
                Directory.CreateDirectory(path);
            }

            // Create .../MyFlgas/Flags is not exist.
            path = MyFlagsFullPath;
            if (!Directory.Exists(path))
            {
                Messenger.AddInfo(string.Format(Messages.MSG_CREATING_DIR_0, path));
                path = MyFlagsPath;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                // Forlder must be named like "Flags" case sensitive!!!!
                Directory.CreateDirectory(MyFlagsFullPath);
            }
        }
示例#5
0
        /// <summary>
        /// Starts the backup of a directory.
        /// </summary>
        /// <param name="dir">The directory to backup.</param>
        /// <param name="name">The name of the backup file.</param>
        /// <param name="backupPath">The path to write the backup to.</param>
        /// <returns>The new name of the backup file.</returns>
        public static string BackupDir(string dir, string name, string backupPath)
        {
            using (var archive = ZipArchive.Create())
            {
                if (name != string.Empty && backupPath != string.Empty)
                {
                    // TODO: Add file/dir wise, not whole dir at once ...
                    foreach (string file in Directory.GetFiles(dir))
                    {
                        string directoryName = Path.GetDirectoryName(file);
                        if (directoryName != null)
                        {
                            string temp =
                                Path.Combine(directoryName.Replace(KSPPathHelper.GetPath(KSPPaths.KSPRoot) + Path.DirectorySeparatorChar, string.Empty),
                                             Path.GetFileName(file));
                            archive.AddEntry(temp, file);
                        }
                    }

                    AddSubDirs(dir, archive);

                    archive.SaveTo(backupPath, CompressionType.None);
                }
                else
                {
                    Messenger.AddInfo(Messages.MSG_BACKUP_CREATION_ERROR);
                }
            }

            return(name);
        }
示例#6
0
        /// <summary>
        /// Reads the backup directory and fills the backup TreeView.
        /// </summary>
        public static void ScanBackupDirectory()
        {
            model.Nodes.Clear();

            try
            {
                if (Directory.Exists(BackupPath))
                {
                    foreach (string file in Directory.EnumerateFiles(BackupPath, "*" + Constants.EXT_ZIP))
                    {
                        string dispTxt = GetBackupDisplayName(file);
                        string note    = GetNote(dispTxt);
                        model.Nodes.Add(new BackupNode(file, dispTxt, note));
                    }

                    SaveBackupSettings();
                }
                else
                {
                    if (string.IsNullOrEmpty(BackupPath))
                    {
                        Messenger.AddInfo(string.Format(Messages.MSG_BACKUP_FOLDER_NOT_FOUND_0, BackupPath));
                    }
                }
            }
            catch (Exception ex)
            {
                Messenger.AddError(string.Format(Messages.MSG_BACKUP_LOAD_ERROR_0, ex.Message), ex);
            }

            View.InvalidateView();
        }
        public static void CreateKMA2Flag()
        {
            // TODO: Get CreateKMAFlag from AppConfig.
            if (!CreateKMAFlag)
            {
                return;
            }

            try
            {
                var fullpath = Path.Combine(MyFlagsFullPath, FLAG_FILENAME);
                if (!File.Exists(fullpath))
                {
                    // Create the folder if it does not exist
                    if (!Directory.Exists(MyFlagsFullPath))
                    {
                        Directory.CreateDirectory(MyFlagsFullPath);
                    }

                    Image image = Resources.KMA2_Flag;
                    image.Save(fullpath);
                    image.Dispose();
                    Messenger.AddInfo(string.Format(Messages.MSG_FLAG_0_ADDED, Path.GetFileNameWithoutExtension(fullpath)));
                }
            }
            catch (Exception ex)
            {
                Messenger.AddError("Error! Can't create KMA² flag.", ex);
            }
        }
示例#8
0
 /// <summary>
 /// Recovers the selected backup.
 /// </summary>
 public static void RecoverSelectedBackup()
 {
     if (SelectedBackup != null && ValidBackupDirectory(BackupPath))
     {
         string file = SelectedBackup.Key;
         if (File.Exists(file))
         {
             string savesPath = KSPPathHelper.GetPath(KSPPaths.Saves);
             if (Directory.Exists(savesPath))
             {
                 string kspPath = KSPPathHelper.GetPath(KSPPaths.KSPRoot);
                 using (IArchive archive = ArchiveFactory.Open(file))
                 {
                     foreach (IArchiveEntry entry in archive.Entries)
                     {
                         string dir = Path.GetDirectoryName(entry.FilePath);
                         CreateNeededDir(dir);
                         entry.WriteToDirectory(Path.Combine(kspPath, dir));
                     }
                 }
                 Messenger.AddInfo(string.Format(Messages.MSG_BACKUP_REINSTALLED, SelectedBackup.Name));
             }
             else
             {
                 Messenger.AddInfo(string.Format(Messages.MSG_FOLDER_NOT_FOUND, savesPath));
             }
         }
     }
     else
     {
         MessageBox.Show(View.ParentForm, Messages.MSG_BACKUP_SRC_MISSING);
     }
 }
 /// <summary>
 /// Adds a node to a list if the node and node name is not null and if the list doesn't contains the node already.
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <param name="list">The list to add to.</param>
 private static void AddNode(PartNode node, List <PartNode> list)
 {
     if (node != null && !string.IsNullOrEmpty(node.Name) && !list.Contains(node))
     {
         Messenger.AddInfo(string.Format(Messages.MSG_PART_FOUND_AND_ADDED_0, node.Name));
         list.Add(node);
     }
 }
        /// <summary>
        /// Opens the Part Editor with the passed PartNode.
        /// </summary>
        /// <param name="partNode">The part node to edit.</param>
        public static void EditPart(PartNode partNode)
        {
            frmPartEditor dlg = new frmPartEditor();

            dlg.Title      = partNode.Title;
            dlg.PartName   = partNode.Name;
            dlg.Category   = partNode.Category;
            dlg.KnownNames = (from PartNode part in allNodes select part.Name).ToList();
            if (dlg.ShowDialog(View.ParentForm) == DialogResult.OK)
            {
                string fullPath = KSPPathHelper.GetAbsolutePath(partNode.FilePath);
                if (File.Exists(fullPath))
                {
                    string allText = File.ReadAllText(fullPath);
                    if (partNode.Name != dlg.NewName)
                    {
                        if (!ChangeParameter(ref allText, partNode.Name, NAME, partNode.Name, dlg.NewName))
                        {
                            return;
                        }

                        Messenger.AddInfo(string.Format(Messages.MSG_NAME_OF_PART_0_CHANGED_1, partNode.Name, dlg.NewName));
                        partNode.Name = dlg.NewName;
                    }
                    if (partNode.Title != dlg.NewTitle)
                    {
                        if (!ChangeParameter(ref allText, partNode.Name, TITLE, partNode.Title, dlg.NewTitle))
                        {
                            return;
                        }

                        Messenger.AddInfo(string.Format(Messages.MSG_TITLE_OF_PART_0_CHANGED_FROM_1_TO_2, partNode.Name, partNode.Title, dlg.NewTitle));
                        partNode.Title = dlg.NewTitle;
                    }
                    if (partNode.Category != dlg.NewCategory)
                    {
                        if (!ChangeParameter(ref allText, partNode.Name, CATEGORY, partNode.Category, dlg.NewCategory))
                        {
                            return;
                        }

                        Messenger.AddInfo(string.Format(Messages.MSG_CATEGORY_OF_PART_0_CHANGED_FROM_1_TO_2, partNode.Name, partNode.Category, dlg.NewCategory));
                        partNode.Category = dlg.NewCategory;

                        foreach (var node in partNode.Nodes)
                        {
                            if (node.Text.StartsWith("Category = "))
                            {
                                node.Text = "Category = " + partNode.Category;
                                break;
                            }
                        }
                    }
                    File.WriteAllText(fullPath, allText);
                }
            }
        }
示例#11
0
        /// <summary>
        /// Creates a Backup of the saves folder with the name "KSPLaunchBackup_{yyyyMMdd_HHmm}.zip".
        /// </summary>
        public static void KSPLaunchBackup()
        {
            Messenger.AddInfo("Backup on KSP launch started.");
            string dir     = KSPPathHelper.GetPath(KSPPaths.Saves);
            string zipPath = dir.Replace(KSPPathHelper.GetPath(KSPPaths.KSPRoot) + Path.DirectorySeparatorChar, string.Empty);
            string name    = String.Format("KSPLaunchBackup_{0}{1}", DateTime.Now.ToString("yyyyMMdd_HHmm"), Constants.EXT_ZIP);

            BackupDirectoryAsync(dir, name, Path.Combine(BackupPath, name), zipPath);
        }
        /// <summary>
        /// Refreshes the Flags tab.
        /// Searches the KSP install dir for flags and adds them to the ListView.
        /// </summary>
        public static void RefreshFlagTab()
        {
            if (ignoreIndexChange)
            {
                return;
            }

            Messenger.AddInfo(Messages.MSG_FLAG_SCAN_STARTED);

            ignoreIndexChange = true;
            string lastFilter = View.SelectedFilter;

            View.ClearAll();
            flags.Clear();

            // add default Filter
            View.AddFilter(FILTER_ALL);
            View.AddFilter(FILTER_MYFLAG);

            View.ShowProcessingIcon = true;
            EventDistributor.InvokeAsyncTaskStarted(Instance);

            AsyncTask <bool> .DoWork(() =>
            {
                SearchDir4FlagsDirs(KSPPathHelper.GetPath(KSPPaths.GameData));
                return(true);
            },
                                     (bool result, Exception ex) =>
            {
                View.ShowProcessingIcon = false;
                EventDistributor.InvokeAsyncTaskDone(Instance);

                if (ex != null)
                {
                    Messenger.AddError(Messages.MSG_ERROR_DURING_FLAG_SCAN, ex);
                }
                else
                {
                    Messenger.AddInfo(Core.Messages.MSG_DONE);
                }

                if (lastFilter != null &&
                    (lastFilter == FILTER_ALL || lastFilter == FILTER_MYFLAG || View.GetGroup(lastFilter) != null))
                {
                    View.SelectedFilter = lastFilter;
                }
                else
                {
                    View.SelectedFilter = FILTER_ALL;
                }

                ignoreIndexChange = false;

                View.FillListView(flags);
            });
        }
        private static CkanMod CreateMod(IArchiveEntry archiveEntry)
        {
            var mod = new CkanMod
            {
                ArchivePath = archiveEntry.FilePath,
                Name        = GetDirectoryName(archiveEntry.FilePath)
            };

            Messenger.AddInfo($"Mod \"{mod.Name}\" created from \"{archiveEntry.FilePath}\"");

            return(mod);
        }
 /// <summary>
 /// Adds the passed ModBrowser to the selection of available MoDBrowser.
 /// </summary>
 /// <param name="modBrowser">The ModBrowser to add.</param>
 internal void AddModBrowser(IKSPMAModBrowser modBrowser)
 {
     if (!cbModBrowser.Items.Cast <ModBrowserInfo>().Any(mb => mb.ModBrowserName == modBrowser.ModBrowserName))
     {
         Messenger.AddInfo(string.Format(Messages.MSG_REGISTER_MODBROWSER_0, modBrowser.ModBrowserName));
         cbModBrowser.Items.Add(new ModBrowserInfo(modBrowser));
         Controls.Add(modBrowser.ModBrowserView);
         modBrowser.ModBrowserView.Dock = DockStyle.Fill;
         modBrowser.ModBrowserView.BringToFront();
         modBrowser.ModBrowserView.Visible = false;
     }
 }
        /// <summary>
        /// Starts the Import of a new flag.
        /// </summary>
        public static void ImportFlag()
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = Constants.IMAGE_FILTER;
            if (dlg.ShowDialog(View.ParentForm) == DialogResult.OK)
            {
                string filename = dlg.FileName;

                try
                {
                    CreateNeededDirectories();

                    // delete file with same name.
                    string savePath = Path.Combine(MyFlagsFullPath, Path.GetFileNameWithoutExtension(filename) + EXTENSION_PNG);
                    if (File.Exists(savePath))
                    {
                        Messenger.AddInfo(string.Format(Messages.MSG_DELETE_EXISTING_FLAG_0, savePath));
                        File.Delete(savePath);
                    }

                    // save image with max flag size to gamedata/myflags/flags/.
                    using (var image = Image.FromFile(filename))
                    {
                        if (image.Size.Width != FLAG_WIDTH || image.Size.Height != FLAG_HEIGHT)
                        {
                            Messenger.AddInfo(Messages.MSG_ADJUSTING_FLAG_SIZE);
                            Bitmap newImage = new Bitmap(FLAG_WIDTH, FLAG_HEIGHT);
                            using (Graphics graphicsHandle = Graphics.FromImage(newImage))
                            {
                                graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                graphicsHandle.DrawImage(image, 0, 0, FLAG_WIDTH, FLAG_HEIGHT);
                            }
                            Messenger.AddInfo(string.Format(Messages.MSG_SAVING_FLAG_0, savePath));
                            newImage.Save(savePath, ImageFormat.Png);
                        }
                        else
                        {
                            Messenger.AddInfo(string.Format(Messages.MSG_COPY_FLAG_0, savePath));
                            image.Save(savePath, ImageFormat.Png);
                        }
                    }

                    AddFlagToList(savePath);
                }
                catch (Exception ex)
                {
                    Messenger.AddError(Messages.MSG_ERROR_FLAG_CREATION_FAILED, ex);
                }

                RefreshFlagTab();
            }
        }
        private static CkanModInfo CreateModInfos(IArchiveEntry archiveEntry, CkanMod ckanMod)
        {
            var ms = new MemoryStream();

            archiveEntry.WriteTo(ms);
            ms.Position = 0;
            using (var sr = new StreamReader(ms))
            {
                var content  = sr.ReadToEnd();
                var modInfos = JsonConvert.DeserializeObject <CkanModInfo>(content);
                Messenger.AddInfo($"ModInfos \"{modInfos.name}\"-\"{modInfos.version}\" created from \"{archiveEntry.FilePath}\"");
                modInfos.Mod     = ckanMod;
                modInfos.version = NormalizeVersion(modInfos.version);
                return(modInfos);
            }
        }
示例#17
0
 private void _AddMessage(string msg, bool error = false, Exception ex = null)
 {
     InvokeIfRequired(() => lblCurrentAction.Text = msg);
     if (!error)
     {
         Messenger.AddInfo(msg);
     }
     else if (ex == null)
     {
         Messenger.AddError(msg);
     }
     else
     {
         Messenger.AddError(msg, ex);
     }
 }
示例#18
0
        /// <summary>
        /// Callback function after a backup.
        /// </summary>
        private static void BackupDirFinished(string name, Exception ex)
        {
            EventDistributor.InvokeAsyncTaskDone(Instance);
            View.ShowProcessing = false;

            if (ex != null)
            {
                Messenger.AddError(Messages.MSG_BACKUP_CREATION_ERROR, ex);
            }
            else
            {
                ScanBackupDirectory();

                Messenger.AddInfo(string.Format(Messages.MSG_BACKUP_COMPLETE, name));
            }
        }
示例#19
0
        private void ResetPatentDestinationIfNecessary(ModNode modNode)
        {
            var parent = modNode.Parent as ModNode;

            if (parent == null)
            {
                return;
            }

            if (!parent.HasDestinationForChilds)
            {
                Messenger.AddInfo(string.Format(Messages.MSG_CONFLICT_SOLVER_RESET_DESTINATION_PARENT_FOLDER_0_1, modNode.Name, modNode.ZipRoot.Name));
                parent._Checked = false;
                ModNodeHandler.SetDestinationPaths(parent, string.Empty);
            }
        }
        /// <summary>
        /// Downloads the Ckan Repository archive to full path.
        /// </summary>
        /// <param name="repo">The Ckan Repository to get the Ckan Repository archive for.</param>
        /// <param name="fullpath">The full path to write the downloaded file to.</param>
        /// <param name="onDownloadComplete">Callback function for the DownloadComplete event.</param>
        /// <param name="onDownloadProgressChanged">Callback function for the DownloadProgressChanged event.</param>
        /// <returns>The new created CkanArchive which was constructed from the downloaded Ckan Repository archive.</returns>
        public static bool DownloadRepositoryArchive(CkanRepository repo, string fullpath, AsyncCompletedEventHandler onDownloadComplete = null, DownloadProgressChangedEventHandler onDownloadProgressChanged = null)
        {
            var async = onDownloadComplete != null;

            Messenger.AddInfo($"Downloading repository archive \"{repo.name}\" from \"{repo.uri.AbsoluteUri}\"...");
            try
            {
                using (var client = new WebClient())
                {
                    if (onDownloadProgressChanged != null)
                    {
                        client.DownloadProgressChanged += onDownloadProgressChanged;
                    }

                    if (onDownloadComplete != null)
                    {
                        client.DownloadFileCompleted += (sender, args) =>
                        {
                            onDownloadComplete(sender, args);
                            Messenger.AddInfo($"Downloading repository archive \"{repo.name}\" done.");
                        }
                    }
                    ;

                    if (async)
                    {
                        client.DownloadFileAsync(repo.uri, fullpath);
                    }
                    else
                    {
                        client.DownloadFile(repo.uri, fullpath);
                    }
                }
            }
            catch (Exception ex)
            {
                Messenger.AddError($"Error during downloading repository archive \"{repo.name}\" Error message: \"{ex.Message}\".", ex);
            }

            if (async)
            {
                return(false);
            }

            Messenger.AddInfo($"Downloading repository archive \"{repo.name}\" done.");
            return(File.Exists(fullpath));
        }
        private void btnLunchKSP_Click(object sender, EventArgs e)
        {
            string fullpath   = KSPPathHelper.GetPath(KSPPaths.KSPExe);
            string fullpath64 = KSPPathHelper.GetPath(KSPPaths.KSPX64Exe);

            try
            {
                if (File.Exists(fullpath64) && cbUse64Bit.Checked)
                {
                    fullpath = fullpath64;
                }

                if (File.Exists(fullpath))
                {
                    WriteKSPSettings();

                    EventDistributor.InvokeStartingKSP(this);

                    Messenger.AddInfo(Messages.MSG_STARTING_KSP);
                    System.Diagnostics.Process kspexe = new System.Diagnostics.Process();
#if __MonoCS__
                    kspexe.StartInfo.UseShellExecute = false;
                    kspexe.StartInfo.EnvironmentVariables.Add("LC_ALL", "C");
#endif
                    kspexe.StartInfo.FileName         = fullpath;
                    kspexe.StartInfo.WorkingDirectory = Path.GetDirectoryName(fullpath);
                    if (rbWindowed.Checked && cbBorderlessWin.Checked)
                    {
                        kspexe.StartInfo.Arguments = PARAM_POPUPWINDOW;
                    }
                    if (cbForceOpenGL.Checked)
                    {
                        kspexe.StartInfo.Arguments += " " + PARAM_FORCE_OPENGL;
                    }

                    kspexe.Start();
                }
                else
                {
                    Messenger.AddError(Messages.MSG_CANT_FIND_KSP_EXE);
                }
            }
            catch (Exception ex)
            {
                Messenger.AddError(Messages.MSG_KSP_LAUNCH_FAILED, ex);
            }
        }
示例#22
0
        private void Export()
        {
            List <ModNode> modsToExport = GetModsToExport();

            if (modsToExport.Count <= 0)
            {
                MessageBox.Show(this, Messages.MSG_NO_MODS_TO_EXPORT, Messages.MSG_TITLE_ATTENTION);
                Messenger.AddInfo(Messages.MSG_NO_MODS_TO_EXPORT);
            }
            else
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.InitialDirectory = OptionsController.DownloadPath;
                dlg.FileName         = RemoveInvalidCharsFromPath(string.Format(MODPACK_FILENAME_TEMPLATE, DateTime.Now.ToShortDateString()));
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    pbExport.Visible = true;
                    AddMessage(string.Format(Messages.MSG_EXPORT_TO_0, dlg.FileName));
                    AsyncTask <bool> .DoWork(() =>
                    {
                        ModPackHandler.MessageCallbackFunction = AddMessage;
                        ModPackHandler.Export(modsToExport, dlg.FileName, cbIncludeMods.Checked);
                        ModPackHandler.MessageCallbackFunction = null;
                        return(true);
                    },
                                             (b, ex) =>
                    {
                        pbExport.Visible = false;
                        if (ex != null)
                        {
                            AddMessage(string.Format(Messages.MSG_ERROR_EXPORT_FAILED_0, ex.Message), true, ex);
                            MessageBox.Show(this, string.Format(Messages.MSG_ERROR_EXPORT_FAILED_0, ex.Message), Messages.MSG_TITLE_ERROR);
                        }
                        else
                        {
                            AddMessage(Messages.MSG_EXPORT_DONE);
                            Close();
                        }
                    });
                }
                else
                {
                    AddMessage(Messages.MSG_EXPORT_ABORTED);
                }
            }
        }
示例#23
0
        /// <summary>
        /// Starts the backup of a directory.
        /// </summary>
        /// <param name="dir">The directory to backup.</param>
        /// <param name="name">Name of the backup file.</param>
        /// <param name="backupPath">The path to write the backup file to.</param>
        /// <param name="zipPath">Base path within the zip archive.</param>
        private static void BackupDirectoryAsync(string dir, string name = "", string backupPath = "", string zipPath = "")
        {
            try
            {
                string nameAuto;
                string backupPathAuto;
                string zipPathAuto;
                nameAuto = CreateBackupFilename(dir, out backupPathAuto, out zipPathAuto);

                if (string.IsNullOrEmpty(name))
                {
                    name = nameAuto;
                }

                if (string.IsNullOrEmpty(backupPath))
                {
                    backupPath = backupPathAuto;
                }

                if (string.IsNullOrEmpty(zipPath))
                {
                    zipPath = zipPathAuto;
                }

                if (!Directory.Exists(BackupPath))
                {
                    Directory.CreateDirectory(BackupPath);
                }

                if (Directory.Exists(dir))
                {
                    EventDistributor.InvokeAsyncTaskStarted(Instance);
                    View.ShowProcessing = true;
                    Messenger.AddInfo(Messages.MSG_BACKUP_STARTED);
                    AsyncTask <string> .DoWork(() => BackupDir(dir, name, backupPath), BackupDirFinished);
                }
                else
                {
                    Messenger.AddInfo(string.Format(Messages.MSG_BACKUP_SRC_FOLDER_NOT_FOUND, dir));
                }
            }
            catch (Exception ex)
            {
                Messenger.AddError(string.Format(Messages.MSG_BACKUP_ERROR, ex.Message), ex);
            }
        }
示例#24
0
        private void InstallParentIfNecessary(ModNode modNode)
        {
            var parent = modNode.Parent as ModNode;

            if (parent == null)
            {
                return;
            }

            if (parent.Checked && !parent.IsInstalled)
            {
                Messenger.AddInfo(string.Format(Messages.MSG_CONFLICT_SOLVER_INSTALL_PARENT_FOLDER_0_1, modNode.Name, modNode.ZipRoot.Name));
                parent._Checked = true;
                ModNodeHandler.ProcessMod(parent, true);
                InstallParentIfNecessary(parent);
            }
        }
        private void WriteKSPSettings()
        {
            string settingsPath = Path.Combine(KSPPathHelper.GetPath(KSPPaths.KSPRoot), PARAM_SETTINGS_CFG);

            if (File.Exists(settingsPath))
            {
                if (ScreenResolution == null)
                {
                    return;
                }

                int      index1  = -1;
                int      index2  = -1;
                string   temp    = string.Empty;
                string   allText = File.ReadAllText(settingsPath);
                string[] size    = ScreenResolution.Split("x");
                if (size.Length == 2)
                {
                    index1  = allText.IndexOf(Constants.SCREEN_WIDTH);
                    index2  = allText.IndexOf(Environment.NewLine, index1);
                    temp    = allText.Substring(index1, index2 - index1);
                    allText = allText.Replace(temp, string.Format(PARAM_0_EQUALS_1, Constants.SCREEN_WIDTH, size[0]));

                    index1  = allText.IndexOf(Constants.SCREEN_HEIGHT);
                    index2  = allText.IndexOf(Environment.NewLine, index1);
                    temp    = allText.Substring(index1, index2 - index1);
                    allText = allText.Replace(temp, string.Format(PARAM_0_EQUALS_1, Constants.SCREEN_HEIGHT, size[1]));
                }

                index1  = allText.IndexOf(Constants.FULLSCREEN);
                index2  = allText.IndexOf(Environment.NewLine, index1);
                temp    = allText.Substring(index1, index2 - index1);
                allText = allText.Replace(temp, string.Format(PARAM_0_EQUALS_1, Constants.FULLSCREEN, rbFullscreen.Checked));
                File.WriteAllText(settingsPath, allText);
                Messenger.AddInfo(Messages.MSG_UPDATE_KSP_SETTINGS);

                settingsFileFound = true;
            }
            else
            {
                Messenger.AddInfo(Messages.MSG_CANT_FIND_KSP_SETTINGS);
                settingsFileFound = false;
            }
        }
示例#26
0
        /// <summary>
        /// Downloads the CKAN Repositories from CkanRepoManager.MasterRepoListURL.
        /// And updates the View.
        /// </summary>
        /// <param name="finishedCallback">Optional callback function. Will be called after finishing the async get.</param>
        public static void RefreshCkanRepositories(Action finishedCallback = null)
        {
            var parent = ModBrowserViewController.View;

            if (parent != null)
            {
                parent.ShowProcessing = true;
            }

            Messenger.AddInfo(Messages.MSG_REFRESHING_REPOSITORIES);
            EventDistributor.InvokeAsyncTaskStarted(Instance);
            AsyncTask <CkanRepositories> .DoWork(() =>
            {
                return(CkanRepoManager.GetRepositoryList());    // CkanRepoManager.MasterRepoListURL);
            },
                                                 (result, ex) =>
            {
                EventDistributor.InvokeAsyncTaskDone(Instance);

                if (parent != null)
                {
                    parent.ShowProcessing = false;
                }

                if (ex != null)
                {
                    Messenger.AddError(string.Format(Messages.MSG_ERROR_DURING_REFRESH_REPOSITORIES_0, ex.Message), ex);
                }
                else
                {
                    // CkanRepository last = View.SelectedRepository;
                    View.Repositories       = result;
                    View.SelectedRepository = result.repositories.FirstOrDefault();     // last;
                }

                Messenger.AddInfo(Messages.MSG_REFRESHING_REPOSITORIES_DONE);

                if (finishedCallback != null)
                {
                    finishedCallback();
                }
            });
        }
示例#27
0
 /// <summary>
 /// Deletes the backup file.
 /// </summary>
 /// <param name="file">The file to delete.</param>
 public static void RemoveBackup(string file)
 {
     if (File.Exists(file))
     {
         try
         {
             File.Delete(file);
             Messenger.AddInfo(string.Format(Messages.MSG_BACKUP_DELETED, Path.GetFileName(file)));
         }
         catch (Exception ex)
         {
             Messenger.AddError(string.Format(Messages.MSG_BACKUP_DELETED_ERROR, Path.GetFileName(file)), ex);
         }
     }
     else
     {
         Messenger.AddInfo(string.Format(Messages.MSG_BACKUP_NOT_FOUND, Path.GetFileName(file)));
     }
 }
示例#28
0
        /// <summary>
        /// Processes all changes mods
        /// Installs or uninstalls them.
        /// </summary>
        public static void ProcessChanges()
        {
            Messenger.AddInfo(Messages.MSG_PROCESSING_STARTED);

            if (model.Nodes != null)
            {
                foreach (var mod in model.Nodes)
                {
                    foreach (var modInfo in mod.Nodes.Cast <CkanNode>().Where(modInfo => modInfo.Added != modInfo.Checked))
                    {
                        // TODO: Do the real work
                        modInfo.Added = modInfo.Checked;
                    }
                }
            }

            Messenger.AddInfo(Messages.MSG_PROCESSING_DONE);

            View.InvalidateView();
        }
示例#29
0
        private void btnDownloadPath_Click(object sender, EventArgs e)
        {
            FolderSelectDialog dlg = new FolderSelectDialog();

            dlg.Title            = Messages.MSG_DOWNLOAD_FOLDER_SELECTION_TITLE;
            dlg.InitialDirectory = DownloadPath;
            if (dlg.ShowDialog(this.Handle))
            {
                DownloadPath = dlg.FileName;
                Messenger.AddInfo(string.Format(Messages.MSG_DOWNLOAD_PATH_CHANGED_0, dlg.FileName));
            }

            ////FolderBrowserDialog dlg = new FolderBrowserDialog();
            ////dlg.SelectedPath = DownloadPath;
            ////if (dlg.ShowDialog(this) == DialogResult.OK)
            ////{
            ////    DownloadPath = dlg.SelectedPath;
            ////    Messenger.AddInfo(string.Format(Messages.MSG_DOWNLOAD_PATH_CHANGED_0, dlg.SelectedPath));
            ////}
        }
        /// <summary>
        /// Adds a Flag to the internal list of flags.
        /// </summary>
        /// <param name="file">Full path to the Flag file.</param>
        private static void AddFlagToList(string file)
        {
            try
            {
                if (File.Exists(file))
                {
                    Image image = null;

                    string extension = Path.GetExtension(file);
                    if (extension.Equals(EXTENSION_DDS, StringComparison.CurrentCultureIgnoreCase))
                    {
                        image = DdsToBitMap(file);
                    }
                    else
                    {
                        image = Image.FromFile(file);
                    }

                    if (image == null)
                    {
                        return;
                    }

                    string groupName = GetGroupName(file);
                    string flagname  = Path.GetFileNameWithoutExtension(file);

                    if (flagname.Equals(Path.GetFileNameWithoutExtension(FLAG_FILENAME), StringComparison.CurrentCultureIgnoreCase))
                    {
                        groupName = KMA2;
                    }

                    var item = View.CreateNewFlagItem(flagname, groupName, image, file);
                    flags.Add(new KeyValuePair <string, ListViewItem>(groupName, item));
                    Messenger.AddInfo(string.Format(Messages.MSG_FLAG_0_ADDED, flagname));
                }
            }
            catch (Exception ex)
            {
                Messenger.AddError(string.Format(Messages.MSG_ERROR_FLAG_0_ADD_FAILED, file), ex);
            }
        }