コード例 #1
0
        /// <summary>
        /// Extracts the first folder name of the path.
        /// </summary>
        /// <param name="path">The path to get the first folder name of.</param>
        /// <returns>The first folder name of the path.</returns>
        private static string GetCraftFolder(string path)
        {
            string folder = KSPPathHelper.GetRelativePath(path).Replace(Constants.KSPFOLDERTAG + Path.DirectorySeparatorChar, string.Empty);

            folder = folder.Substring(0, folder.IndexOf(Path.DirectorySeparatorChar));
            return(folder);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
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);
        }
コード例 #4
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();
            }
        }
コード例 #5
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);
     }
 }
コード例 #6
0
 /// <summary>
 /// Creates a backup of the saves folder of the current selected KSP install.
 /// </summary>
 public static void BackupSaves()
 {
     if (ValidBackupDirectory(BackupPath))
     {
         BackupDirectoryAsync(KSPPathHelper.GetPath(KSPPaths.Saves));
     }
 }
コード例 #7
0
        /// <summary>
        /// Loads all available languages.
        /// </summary>
        protected static void LoadLanguages()
        {
            Log.AddDebugS("Loading languages ...");

            // Try load languages.
            bool langLoadFailed = false;

            try
            {
                Localizer.GlobalInstance.DefaultLanguage = "eng";
                langLoadFailed = !Localizer.GlobalInstance.LoadLanguages(new[]
                {
                    KSPPathHelper.GetPath(KSPPaths.LanguageFolder),
                    Path.Combine(KSPPathHelper.GetPath(KSPPaths.KSPMA_Plugins), Constants.LANGUAGE_FOLDER)
                }, true);
            }
            catch (Exception ex)
            {
                Log.AddErrorS("Error in MainController.LoadLanguages()", ex);
                langLoadFailed = true;
            }

            if (langLoadFailed)
            {
                MessageBox.Show("Can not load languages!" + Environment.NewLine + "Fall back to defalut language: English", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Localizer.GlobalInstance.Clear();
            }

            Log.AddDebugS(string.Format("Loading languages done. ({0})", string.Join(", ", Localizer.GlobalInstance.AvailableLanguages)));
        }
コード例 #8
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();
        }
コード例 #9
0
        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;
            }
        }
コード例 #10
0
 private void OpenFolder(ModNode node)
 {
     if (node != null && !node.IsFile && node.IsInstalled)
     {
         OptionsController.OpenFolder(KSPPathHelper.GetAbsolutePath(SelectedNode.Destination));
     }
 }
コード例 #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);
        }
コード例 #12
0
        /// <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);
                }
            }
        }
コード例 #13
0
        /// <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);
            });
        }
コード例 #14
0
        /// <summary>
        /// First run initialization of config directory.
        /// </summary>
        protected static void CreateConfigDir()
        {
            string path = KSPPathHelper.GetPath(KSPPaths.AppConfig);

            path = Directory.GetParent(path).ToString();
            if (!Directory.Exists(path))
            {
                Messenger.AddDebug("Creating config directory: " + path);
                Directory.CreateDirectory(path);
            }
        }
コード例 #15
0
 /// <summary>
 /// Checks if the ModNode is installed.
 /// </summary>
 /// <returns>True if Mod Node is installed.</returns>
 public bool IsModNodeInstalled()
 {
     if (IsFile)
     {
         return(!string.IsNullOrEmpty(Destination) && File.Exists(KSPPathHelper.GetAbsolutePath(Destination)));
     }
     else
     {
         return(!string.IsNullOrEmpty(Destination) && Directory.Exists(KSPPathHelper.GetAbsolutePath(Destination)));
     }
 }
コード例 #16
0
        /// <summary>
        /// Opens the SelectFolderDialog to select a folder to backup
        /// and Starts the backup process async.
        /// </summary>
        public static void NewBackup()
        {
            if (!ValidBackupDirectory(BackupPath))
            {
                return;
            }

            FolderSelectDialog dlg = new FolderSelectDialog();

            dlg.Title            = "Source folder selection";
            dlg.InitialDirectory = KSPPathHelper.GetPath(KSPPaths.KSPRoot);
            if (dlg.ShowDialog(View.ParentForm.Handle))
            {
                BackupDirectoryAsync(dlg.FileName);
            }
        }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
        /// <summary>
        /// Returns the new path for the craft.
        /// </summary>
        /// <param name="craftNode">The CraftNode to get a new path for.</param>
        /// <param name="newType">the new type of the craft.</param>
        /// <returns>The new path for the craft.</returns>
        private static string GetNewPath(CraftNode craftNode, string newType)
        {
            string fullPath = KSPPathHelper.GetAbsolutePath(craftNode.FilePath);
            int    index    = fullPath.ToLower().IndexOf(Path.DirectorySeparatorChar + craftNode.Type.ToLower() + Path.DirectorySeparatorChar);

            if (index > -1)
            {
                string start = fullPath.Substring(0, index + 1);
                string end   = fullPath.Substring(index + 5);

                return(Path.Combine(Path.Combine(start, newType.ToUpper()), end));
            }
            else
            {
                return(fullPath);
            }
        }
コード例 #19
0
        /// <summary>
        /// Adds the sub directory to the Archive.
        /// </summary>
        /// <param name="parentDir">Parent directory to scan for sub directories and files.</param>
        /// <param name="archive">The Archive to add the directories and files to.</param>
        private static void AddSubDirs(string parentDir, ZipArchive archive)
        {
            foreach (string subDir in Directory.GetDirectories(parentDir))
            {
                foreach (string file in Directory.GetFiles(subDir))
                {
                    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(subDir, archive);
            }
        }
コード例 #20
0
        /// <summary>
        /// Loads and registers all SiteHandler.
        /// </summary>
        protected static void LoadSiteHandler()
        {
            // Add default SiteHandler
            var siteHandlers = PluginLoader.GetPlugins <ISiteHandler>(new[] { Assembly.GetExecutingAssembly() });

            foreach (ISiteHandler handler in siteHandlers)
            {
                SiteHandlerManager.RegisterSiteHandler(handler);
            }

            // Add additional SiteHandlers
            siteHandlers = PluginLoader.LoadPlugins <ISiteHandler>(KSPPathHelper.GetPath(KSPPaths.KSPMA_Plugins));
            foreach (ISiteHandler handler in siteHandlers)
            {
                SiteHandlerManager.RegisterSiteHandler(handler);
            }
        }
コード例 #21
0
        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;
            }
        }
コード例 #22
0
        /// <summary>
        /// Creates a new default TreeNodePart.
        /// </summary>
        /// <param name="file">The full path of the part cfg file.</param>
        /// <returns>The new created PartNode from the passed file.</returns>
        private static PartNode CreateNewPartNode(string file)
        {
            PartNode partNode = new PartNode();

            partNode.FilePath = KSPPathHelper.GetRelativePath(file);
            if (file.Contains(Constants.GAMEDATA))
            {
                string mod = file.Substring(file.IndexOf(Constants.GAMEDATA) + 9);
                mod          = mod.Substring(0, mod.IndexOf(Path.DirectorySeparatorChar));
                partNode.Mod = mod;

                if (!allModFilter.Contains(mod))
                {
                    allModFilter.Add(mod);
                }
            }

            return(partNode);
        }
コード例 #23
0
        /// <summary>
        /// Deletes older config paths and files.
        /// </summary>
        protected static void DeleteOldAppConfigs()
        {
            string path = KSPPathHelper.GetPath(KSPPaths.AppConfig);

            string[] dirs = Directory.GetDirectories(Path.GetDirectoryName(path));
            foreach (string dir in dirs)
            {
                try
                {
                    if (!Directory.Exists(dir))
                    {
                        continue;
                    }

                    Directory.Delete(dir, true);
                }
                catch (Exception)
                { }
            }
        }
コード例 #24
0
 /// <summary>
 /// Saves the KSPConfig to the selected KSP folder.
 /// </summary>
 public static void SaveKSPConfig()
 {
     try
     {
         string path = KSPPathHelper.GetPath(KSPPaths.KSPConfig);
         if (path != string.Empty && Directory.Exists(Path.GetDirectoryName(path)))
         {
             Messenger.AddInfo(Messages.MSG_SAVING_KSP_MOD_SETTINGS);
             KSPConfig.Save(path, ModSelectionController.Mods);
         }
         else
         {
             Messenger.AddError(Messages.MSG_KSP_MOD_SETTINGS_PATH_INVALID);
         }
     }
     catch (Exception ex)
     {
         Messenger.AddError(Messages.MSG_ERROR_DURING_SAVING_KSP_MOD_SETTINGS, ex);
         ShowAdminRightsDlg(ex);
     }
 }
コード例 #25
0
 /// <summary>
 /// Saves the AppConfig to "c:\ProgramData\..."
 /// </summary>
 protected static void SaveAppConfig()
 {
     try
     {
         Messenger.AddInfo(Messages.MSG_SAVING_KSPMA_SETTINGS);
         string path = KSPPathHelper.GetPath(KSPPaths.AppConfig);
         if (path != string.Empty && Directory.Exists(Path.GetDirectoryName(path)))
         {
             AdminConfig.Save(path);
         }
         else
         {
             Messenger.AddError(Messages.MSG_KSPMA_SETTINGS_PATH_INVALID);
         }
     }
     catch (Exception ex)
     {
         Messenger.AddError(Messages.MSG_ERROR_DURING_SAVING_KSPMA_SETTINGS, ex);
         ShowAdminRightsDlg(ex);
     }
 }
コード例 #26
0
        /// <summary>
        /// Creates the name for a backup file.
        /// </summary>
        /// <param name="dir">The path to backup to.</param>
        /// <param name="fullpath">Full path of the created backup file.</param>
        /// <param name="zipPath">Path within the zip archive.</param>
        /// <returns>The created name of the backup file.</returns>
        private static string CreateBackupFilename(string dir, out string fullpath, out string zipPath)
        {
            // create the name of the backupfile from the backup directory
            string name     = dir.Substring(dir.LastIndexOf(Path.DirectorySeparatorChar) + 1, dir.Length - (dir.LastIndexOf(Path.DirectorySeparatorChar) + 1));
            string filename = String.Format("{0}_{1}{2}", name, DateTime.Now.ToString("yyyyMMdd_HHmm"), Constants.EXT_ZIP);

            fullpath = Path.Combine(BackupPath, filename);

            // get zip intern dir
            zipPath = dir.Replace(KSPPathHelper.GetPath(KSPPaths.KSPRoot) + Path.DirectorySeparatorChar, string.Empty);

            // add _(x) to the filename if the file already exists.
            int i = 1;

            while (File.Exists(fullpath))
            {
                fullpath = Path.GetDirectoryName(fullpath) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(fullpath) + "_" + (i++).ToString("00") + Path.GetExtension(fullpath);
            }

            return(name);
        }
コード例 #27
0
        /// <summary>
        /// This method gets called when your Controller should be initialized.
        /// Perform additional initialization of your UserControl here.
        /// </summary>
        protected static void Initialize()
        {
            Messenger.AddListener(Instance);

            EventDistributor.AsyncTaskStarted += AsyncTaskStarted;
            EventDistributor.AsyncTaskDone    += AsyncTaskDone;
            EventDistributor.LanguageChanged  += LanguageChanged;
            EventDistributor.KSPRootChanging  += KSPRootChanging;
            EventDistributor.KSPRootChanged   += KSPRootChanged;
            EventDistributor.KSPMAStarted     += KSPMAStarted;

            CreateConfigDir();
            LoadConfigs();

            LoadPlugins();

            View.TapOrder = LastTabOrder;

            OptionsController.AvailableLanguages = Localizer.GlobalInstance.AvailableLanguages;
            OptionsController.SelectedLanguage   = Localizer.GlobalInstance.CurrentLanguage;

            LoadSiteHandler();

            if (!KSPPathHelper.IsKSPInstallFolder(OptionsController.SelectedKSPPath))
            {
                frmWelcome dlg = new frmWelcome();
                if (dlg.ShowDialog(View) != DialogResult.OK)
                {
                    View.Close();
                    return;
                }

                OptionsController.AddKSPPath(dlg.KSPPath);
                OptionsController.SelectedKSPPath = dlg.KSPPath;
            }

            // Initializing is done.
            EventDistributor.InvokeKSPMAStarted(Instance);
        }
コード例 #28
0
        /// <summary>
        /// Loads the KSPConfig from the selected KSP folder.
        /// </summary>
        protected static void LoadKSPConfig()
        {
            ModSelectionController.ClearMods();

            string configPath = KSPPathHelper.GetPath(KSPPaths.KSPConfig);

            if (File.Exists(configPath))
            {
                Messenger.AddInfo(Messages.MSG_LOADING_KSP_MOD_CONFIGURATION);
                List <ModNode> mods = new List <ModNode>();
                KSPConfig.Load(configPath, ref mods);
                ModSelectionController.AddMods(mods.ToArray());
                ModSelectionController.SortModSelection();
            }
            else
            {
                Messenger.AddInfo(Messages.MSG_KSP_MOD_CONFIGURATION_NOT_FOUND);
            }

            ModSelectionController.RefreshCheckedStateAllMods();
            Messenger.AddInfo(Messages.MSG_DONE);
        }
コード例 #29
0
        private void btnSelectFolder_Click(object sender, EventArgs e)
        {
            FolderSelectDialog dlg = new FolderSelectDialog();

            dlg.Title = Messages.MSG_KSP_INSTALL_FOLDER_SELECTION;
            if (dlg.ShowDialog(this.Handle))
            {
                if (KSPPathHelper.IsKSPInstallFolder(dlg.FileName))
                {
                    btnFinish.Enabled = true;
                    tbKSPPath.Text    = dlg.FileName;
                }
                else
                {
                    MessageBox.Show(this, Messages.MSG_PLS_SELECT_VALID_KSP_INSTALL_FOLDER, Messages.MSG_TITLE_ATTENTION);
                }
            }
            else
            {
                btnFinish.Enabled = false;
            }
        }
コード例 #30
0
        /// <summary>
        /// Removes the selected craft
        /// </summary>
        public static void RemoveSelectedCraft(CraftNode craftNode)
        {
            string  craftPath = KSPPathHelper.GetAbsolutePath(craftNode.FilePath);
            ModNode node      = ModSelectionTreeModel.SearchNodeByDestination(craftNode.FilePath, ModSelectionController.Model);

            DialogResult dlgResult = DialogResult.Cancel;

            if (node == null)
            {
                dlgResult = MessageBox.Show(View.ParentForm, Messages.MSG_CRAFT_NOT_FROM_MOD_DELETE_WARNING, string.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            }

            if (node != null || dlgResult == DialogResult.Yes)
            {
                if (File.Exists(craftPath))
                {
                    File.Delete(craftPath);
                    Messenger.AddInfo(string.Format(Messages.MSG_CRAFT_0_DELETED, craftPath));

                    if (node != null)
                    {
                        Messenger.AddInfo(string.Format(Messages.MSG_MODSELECTION_UPDATED_PART_0, node.Name));
                        node.Checked  = false;
                        node.NodeType = NodeType.UnknownFile;
                    }

                    model.Nodes.Remove(craftNode);

                    foreach (CraftNode pNode in craftNode.Nodes)
                    {
                        if (pNode.RelatedPart != null)
                        {
                            pNode.RelatedPart.RemoveCraft(craftNode);
                            Messenger.AddInfo(string.Format(Messages.MSG_PARTTAB_UPDATED_PART_0, pNode.RelatedPart.Name));
                        }
                    }
                }
            }
        }