Пример #1
0
        //Open a new project from the given path
        public void OpenProject(string path)
        {
            if (!Directory.Exists(path))
            {
                MessageBox.Show("This project no longer exists!", "Invalid project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                foreach (Project p in Projects)
                {
                    if (p.path.Equals(path))
                    {
                        Projects.Remove(p);
                        UpdateProjects(true, false);
                        return;
                    }
                }
                return;
            }
            string[] files        = Directory.GetFiles(path);
            bool     gradleFound  = false;
            string   mcVersion    = "";
            string   forgeVersion = "";
            string   mcpVersion   = "";

            foreach (string file in files)
            {
                if (file.Contains("gradlew.bat"))
                {
                    gradleFound = true;
                }
                if (file.Contains("build.gradle"))
                {
                    string[] data         = File.ReadAllLines(file);
                    bool     checkVersion = false;
                    BuildFile.ResetText();
                    foreach (string line in data)
                    {
                        if (checkVersion)
                        {
                            if (line.Contains("version") && line.Contains("="))
                            {
                                string version = line.Split('\"')[1];
                                mcVersion    = version.Split('-')[0];
                                forgeVersion = version.Split('-')[1];
                            }
                        }
                        if (line.Contains("minecraft {") && !checkVersion)
                        {
                            checkVersion = true;
                        }
                        else if (line.Contains("}") && checkVersion)
                        {
                            checkVersion = false;
                        }
                        if (line.Contains("mappings = "))
                        {
                            mcpVersion = Regex.Match(line, "\"([^\"]*)\"").Value.Replace("\"", "");
                        }
                    }
                    foreach (string line in data)
                    {
                        AddBuildFileText(line);
                    }
                    BuildFile.ReadOnly = false;
                }
            }
            if (gradleFound && !string.IsNullOrWhiteSpace(mcVersion) && !string.IsNullOrWhiteSpace(forgeVersion) && !string.IsNullOrWhiteSpace(mcpVersion))
            {
                Project p = new Project(path, mcVersion, forgeVersion, mcpVersion);
                Text = "Forge Mod Builder - " + path;
                bool    shouldadd = true;
                Project p2        = p;
                foreach (Project project in Projects)
                {
                    if (project.path.Equals(p.path))
                    {
                        shouldadd = false;
                        p2        = project;
                    }
                }
                if (!shouldadd)
                {
                    Projects.Remove(p2);
                }
                Projects.Insert(0, p);

                CurrentProject = p;
                UpdateProjects(true, false);
                if (Options.ContainsKey("clear_console_on_project_open") && (bool)Options["clear_console_on_project_open"])
                {
                    Console.Text = string.Empty;
                }
                System.Console.WriteLine("Loaded project: " + p);
                AddConsoleText("Loaded project: " + p);
                MessageBox.Show("Successfully loaded project!", "Loaded Project!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Please choose a valid forge project!", "Invalid Project!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }