public static ChangeProjectVersionMenu ShowChangeProjectVersionMenu()
 {
     if (Program.INSTANCE.CurrentProject != null)
     {
         ChangeProjectVersionMenu menu = new ChangeProjectVersionMenu();
         menu.Show();
         return(menu);
     }
     else
     {
         MessageBox.Show("Please open a project!", "No open project", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(null);
     }
 }
Ejemplo n.º 2
0
        //Update the projects in the file or in the variable
        public void UpdateProjects(bool saveFile, bool readFromFile)
        {
            if (saveFile)                          //If you want to save
            {
                if (File.Exists(ProjectsFilePath)) //Make sure the file exists
                {
                    JsonSerializer js = new JsonSerializer();
                    js.NullValueHandling = NullValueHandling.Ignore;
                    using (StreamWriter sw = new StreamWriter(ProjectsFilePath))
                        using (JsonWriter jw = new JsonTextWriter(sw))
                        {
                            js.Serialize(jw, Projects); //Write all the data in Projects to the file
                        }
                }
                else //The file does not exist so create it
                {
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder")) //Does the folder not exist?
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder"); //Create the folder
                    }
                    File.Create(ProjectsFilePath).Dispose();
                    UpdateProjects(saveFile, readFromFile); //Recall the method now that it can find the file
                }
            }
            if (readFromFile)                      //If you want to read data from the file
            {
                if (File.Exists(ProjectsFilePath)) //Make srue the file exists
                {
                    JsonSerializer js = new JsonSerializer();
                    js.NullValueHandling = NullValueHandling.Ignore;
                    using (StreamReader sr = new StreamReader(ProjectsFilePath))
                        using (JsonReader jr = new JsonTextReader(sr))
                        {
                            Projects = js.Deserialize <List <Project> >(jr); //Read the projects
                        }
                    if (Projects == null)
                    {
                        Projects = new List <Project>(); //If the file was empty, initialise Projects to a blank list
                    }
                }
                else //If the file did not exist
                {
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder")) //Does the folder not exist?
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/ForgeModBuilder"); //Create the folder
                    }
                    File.Create(ProjectsFilePath).Dispose();
                    UpdateProjects(saveFile, readFromFile); //Recall the method now that it can find the file
                }
            }

            //Clear all the menu items which allow you to load that project and run the action as well
            OpenProjectMenuItem.DropDownItems.Clear();
            BuildProjectMenuItem.DropDownItems.Clear();
            SetupProjectMenuItem.DropDownItems.Clear();
            UpdateProjectMenuItem.DropDownItems.Clear();
            ChangeProjectVersionMenuItem.DropDownItems.Clear();
            RefreshProjectMenuItem.DropDownItems.Clear();
            foreach (Project p in Projects) //Add a dropdown for each project
            {
                ToolStripMenuItem i = new ToolStripMenuItem(p.path);
                i.Click += (sender, e) =>
                {
                    if (CurrentProject != p)
                    {
                        OpenProject(p.path); //Make it open the current project if it is not already open
                    }
                };
                OpenProjectMenuItem.DropDownItems.Add(i);
                i        = new ToolStripMenuItem(p.path);
                i.Click += (sender, e) =>
                {
                    if (CurrentProject != p)
                    {
                        OpenProject(p.path); //Make it open the current project if it is not already open
                    }
                    BuildProject();
                };
                BuildProjectMenuItem.DropDownItems.Add(i);
                i        = new ToolStripMenuItem(p.path);
                i.Click += (sender, e) =>
                {
                    if (CurrentProject != p)
                    {
                        OpenProject(p.path); //Make it open the current project if it is not already open
                    }
                    SetupProject("");
                };
                SetupProjectMenuItem.DropDownItems.Add(i);
                i        = new ToolStripMenuItem(p.path);
                i.Click += (sender, e) =>
                {
                    if (CurrentProject != p)
                    {
                        OpenProject(p.path); //Make it open the current project if it is not already open
                    }
                    NewProjectMenu.SetupVersions();
                    UpdateProject(NewProjectMenu.Versions[CurrentProject.mcVersion].First(), true);
                };
                UpdateProjectMenuItem.DropDownItems.Add(i);
                i        = new ToolStripMenuItem(p.path);
                i.Click += (sender, e) =>
                {
                    if (CurrentProject != p)
                    {
                        OpenProject(p.path); //Make it open the current project if it is not already open
                    }
                    ChangeProjectVersionMenu.ShowChangeProjectVersionMenu();
                };
                ChangeProjectVersionMenuItem.DropDownItems.Add(i);
                i        = new ToolStripMenuItem(p.path);
                i.Click += (sender, e) =>
                {
                    if (CurrentProject != p)
                    {
                        OpenProject(p.path); //Make it open the current project if it is not already open
                    }
                    RefreshProject();
                };
                RefreshProjectMenuItem.DropDownItems.Add(i);
            }
        }
Ejemplo n.º 3
0
 private void ChangeProjectVersionClick(object sender, EventArgs e)
 {
     ChangeProjectVersionMenu.ShowChangeProjectVersionMenu();
 }