Пример #1
0
 /// <summary>
 /// Removes a craft and its related info
 /// </summary>
 /// <param name="craft"></param>
 private void RemoveCraft(CraftInfo craft)
 {
     Crafts.Remove(craft);
     //olvCraftList.SmallImageList.Images.Remove(craft.Thumb);
     //olvCraftList.LargeImageList.Images.Remove(craft.Thumb);
 }
Пример #2
0
 public bool Equals(CraftInfo toCompare)
 {
     return Hash.Equals(toCompare.Hash);
 }
Пример #3
0
 /// <summary>
 /// Adds thumbnail images for each craft to the imageLists and adds the craft to the crafts list.
 /// </summary>
 /// <param name="craft"></param>
 private void AddCraft(CraftInfo craft)
 {
     Crafts.Add(craft);
     SmallImageList.Images.Add(craft.ThumbName, craft.Thumb);
     LargeImageList.Images.Add(craft.ThumbName, craft.Thumb);
 }
Пример #4
0
 public bool Equals(CraftInfo toCompare)
 {
     return(Hash.Equals(toCompare.Hash));
 }
Пример #5
0
        /// <summary>
        /// Reads a craft file and gets extra info from it such as the description,
        /// latest game version, and part counts.
        /// </summary>
        public static void GetCraftInfo(CraftInfo craft, string path)
        {
            var file = File.ReadAllLines(path);

            int count = 0;

            foreach (var line in file)
            {
                if (craft.CraftName == null && line.Contains("ship"))
                {
                    craft.CraftName = line.Split('=')[1].Trim();
                    continue;
                }

                if (craft.Description == null && line.Contains("description"))
                {
                    craft.Description = line.Split('=')[1].Trim();
                    continue;
                }

                if (craft.Version == null && line.Contains("version"))
                {
                    craft.Version = line.Split('=')[1].Trim();
                    continue;
                }

                if (craft.Building == null && line.Contains("type"))
                {
                    craft.Building = line.Split('=')[1].Trim();
                    continue;
                }

                if (line.Equals("PART"))
                    count++;

            }
            craft.PartCount = count.ToString();
        }
Пример #6
0
 /// <summary>
 /// Loads all craft files from a specific folder and adds them to the list view.
 /// </summary>
 /// <param name="craftFiles">Array of paths to craft files from a save.</param>		
 private void GetCraftInFolder(string[] craftFiles)
 {
     foreach (var craft in craftFiles)
     {
         CraftInfo ci = new CraftInfo(craft);
         AddCraft(ci);
     }
 }
Пример #7
0
        /// <summary>
        /// Copies a craft file from a non-KSP folder into a given save folder.
        /// </summary>
        /// <param name="targetSave"></param>
        /// <param name="sourceCraftPath"></param>
        private void CopyNewCraft(string targetSave, string sourceCraftPath)
        {
            try
            {
                CraftInfo craftData = new CraftInfo(sourceCraftPath);
                CraftInfo.GetCraftInfo(craftData, sourceCraftPath);

                // If the target save is the Hangar, build the correct folder path, otherwise build from the craftInfo
                var destinationFolder = Path.Combine(Util.GetPathToShipsFolder(targetSave), craftData.Building);

                var destinationPath = CopyCraftCheck(craftData, destinationFolder);

                var ci = new CraftInfo(destinationPath);
                AddCraft(ci);
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
                CKAN.Main.Instance.AddLogMessage(ex.Message);
            }
        }
Пример #8
0
        /// <summary>
        /// Copies an existing craft file from one folder to another, checking if the file exists and
        /// overwriting or renaming as necessary depending on settings. Copies and renames thumbnail to match new craft.
        /// </summary>
        /// <param name="targetSave">Folder name of the save to copy into.</param>
        /// <param name="sourceCraft">CraftInfo of the craft file to be copied.</param>
        private void CopyExistingCraft(string targetSave, CraftInfo sourceCraft)
        {
            // In the event that multiple files are selected from multiple saves, ensure that
            // files from the current save aren't copied into themselves.
            if (sourceCraft.SaveName.Equals(targetSave)) return;

            try
            {
                // If the target save is the Hangar, build the correct folder path, otherwise build from the craftInfo
                var destinationFolder = Path.Combine(Util.GetPathToShipsFolder(targetSave), sourceCraft.Building);

                var destinationPath = CopyCraftCheck(sourceCraft, destinationFolder);

                // Create new craft model for the new location
                var ci = new CraftInfo(destinationPath);

                // Copy the existing thumbnail and rename it for the new save
                var thumbOld = Path.Combine(Util.ThumbsDir, sourceCraft.ThumbName);
                var thumbNew = Path.Combine(Util.ThumbsDir, ci.ThumbName);
                if (!File.Exists(thumbNew) && File.Exists(thumbOld))
                {
                    File.Copy(thumbOld, thumbNew);
                }

                AddCraft(ci);
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
                CKAN.Main.Instance.AddLogMessage(ex.Message);
            }
        }
Пример #9
0
        /// <summary>
        /// Copies a source file to a destination file, checking overwrite rules and renaming as necessary
        /// </summary>
        /// <param name="sourceCraft">CraftInfo of source craft.</param>
        /// <param name="destinationFolder">Folder path of destination save.</param>
        private string CopyCraftCheck(CraftInfo sourceCraft, string destinationFolder)
        {
            // If allowed to overwrite, job is easy
            if (OverwriteFiles)
            {
                var destination = Path.Combine(destinationFolder, sourceCraft.FileName);
                File.Copy(sourceCraft.FilePath, destination, true);
                return destination;
            }

            // Get the base filename of the craft, its extension, and the new full path of destination.
            // While new full path exists, append count value to path and check again.
            // When filename doesn't exist, rename file
            int count = 1;
            string fileNameOnly = Path.GetFileNameWithoutExtension(sourceCraft.FileName);
            string extension = Path.GetExtension(sourceCraft.FileName);
            string newFullPath = Path.Combine(destinationFolder, sourceCraft.FileName);

            while (File.Exists(newFullPath))
            {
                string tempFileName = string.Format("{0}_{1}", fileNameOnly, count++);
                newFullPath = Path.Combine(destinationFolder, tempFileName + extension);
            }
            File.Copy(sourceCraft.FilePath, newFullPath, false);
            return newFullPath;
        }
Пример #10
0
 /// <summary>
 /// Adds thumbnail images for each craft to the imageLists and adds the craft to the crafts list.
 /// </summary>
 /// <param name="craft"></param>
 private void AddCraft(CraftInfo craft)
 {
     Crafts.Add(craft);
     SmallImageList.Images.Add(craft.ThumbName, craft.Thumb);
     LargeImageList.Images.Add(craft.ThumbName, craft.Thumb);
 }