Esempio n. 1
0
 public StringValue OriginatingEditor()
 {
     if (ShipConstruction.ShipConfig != null)
     {
         EditorFacility fac = ShipConstruction.ShipType;
         return(fac.ToString().ToUpper());
     }
     return("");
 }
        //Transfer craft to VAB/SPH/Subassemblies
        public string transfer_to(EditorFacility facility)
        {
            string new_path = "";

            if (facility == EditorFacility.SPH)
            {
                new_path = Paths.joined(CraftManager.ksp_root, "saves", save_dir, "Ships", "SPH", file_name + ".craft");
            }
            else if (facility == EditorFacility.VAB)
            {
                new_path = Paths.joined(CraftManager.ksp_root, "saves", save_dir, "Ships", "VAB", file_name + ".craft");
            }
            else if (facility == EditorFacility.None)
            {
                new_path = Paths.joined(CraftManager.ksp_root, "saves", save_dir, "Subassemblies", file_name + ".craft");
            }
            if (String.IsNullOrEmpty(new_path))
            {
                return("Unexpected error");
            }
            if (File.Exists(new_path))
            {
                string msg = "A craft with this name already exists in " + (facility == EditorFacility.None ? "Subassemblies" : "the " + facility.ToString());
                return(msg);
            }
            else
            {
                try{
                    ConfigNode nodes = ConfigNode.Load(path);
                    nodes.SetValue("type", facility.ToString());
                    nodes.Save(new_path);
                }
                catch (Exception e) {
                    return("Unable to move craft; " + e.Message);
                }
                List <string> tags           = Tags.untag_craft(this);
                FileInfo      thumbnail_file = new FileInfo(thumbnail_path());

                File.Delete(path);
                initialize(new_path, stock_craft);
                Tags.tag_craft(this, tags);
                if (thumbnail_file.Exists)
                {
                    thumbnail_file.MoveTo(thumbnail_path());
                    thumbnail = null;
                }
                if (CraftManager.main_ui)
                {
                    CraftManager.main_ui.refresh();
                }
                return("200");
            }
        }