public generateSQL ( string dir, bool deleteFile = true, string>.Dictionary |
||
dir | string | |
deleteFile | bool | |
addSettings | string>.Dictionary | |
리턴 | bool |
public bool openProjDir(string dir) { try { // Check if the directory exists. Also should contain a package_info.xml. if (!Directory.Exists(dir)) return false; // Start an instance of the mod editor. modEditor me = new modEditor(); if (!File.Exists(dir + "/data.sqlite")) { MessageBox.Show("A required database file was not found in your project. It will now be generated.", "Loading Project", MessageBoxButtons.OK, MessageBoxIcon.Information); me.generateSQL(dir); } me.workingDirectory = dir; me.conn = new SQLiteConnection("Data Source=\"" + dir + "/data.sqlite\";Version=3;"); me.conn.Open(); me.hasConn = true; me.refreshInstructionTree(); me.refreshExtractionTree(); me.reloadSettings(); // Checks. if (!me.settings.ContainsKey("modName") || !me.settings.ContainsKey("mbVersion") || !me.settings.ContainsKey("ignoreInstructions") || !me.settings.ContainsKey("autoGenerateModID") || !me.settings.ContainsKey("includeModManLine")) { MessageBox.Show("Your project does not include all the required settings. Please try to repair your project and try again.", "Loading Project", MessageBoxButtons.OK, MessageBoxIcon.Error); me.conn.Close(); me.Close(); return false; } // Compare the versions Version lmver = new Version(Properties.Settings.Default.minMbVersion); Version mver = new Version(me.settings["mbVersion"]); int status = mver.CompareTo(lmver); // If the status is equal to or bigger than 0 we are running the latest version. if (status < 0) { MessageBox.Show("Your project is generated with an older version of Mod Builder, which used a different format. Please repair your project and try again.", "Loading Project", MessageBoxButtons.OK, MessageBoxIcon.Error); me.conn.Close(); me.Close(); return false; } me.modID.Text = me.settings["modID"]; me.modName.Text = me.settings["modName"]; me.modType.SelectedItem = me.settings["modType"]; me.modVersion.Text = me.settings["modVersion"]; me.authorName.Text = me.settings["modUser"]; me.modCompatibility.Text = me.settings["modCompat"]; me.Text = me.settings["modName"] + " - Mod Builder"; if (me.settings["ignoreInstructions"] == "true") me.ignoreInstructions.Checked = true; if (me.settings["autoGenerateModID"] == "true") me.genPkgID.Checked = true; if (me.settings["includeModManLine"] == "true") me.includeModManLine.Checked = true; // Also load the readme.txt. if (File.Exists(dir + "/Package/readme.txt")) me.modReadme.Text = File.ReadAllText(dir + "/Package/readme.txt"); if (File.Exists(dir + "/Package/install.php")) me.customCodeInstall.Text = File.ReadAllText(dir + "/Package/install.php"); if (File.Exists(dir + "/Package/uninstall.php")) me.customCodeUninstall.Text = File.ReadAllText(dir + "/Package/uninstall.php"); if (File.Exists(dir + "/Package/installDatabase.php")) me.installDatabaseCode.Text = File.ReadAllText(dir + "/Package/installDatabase.php"); if (File.Exists(dir + "/Package/uninstallDatabase.php")) me.uninstallDatabaseCode.Text = File.ReadAllText(dir + "/Package/uninstallDatabase.php"); me.Show(); // Log this to the recent projects file. return true; } catch (Exception e) { MessageBox.Show(e.ToString()); return false; } }
private void repairAProjectToolStripMenuItem_Click(object sender, EventArgs e) { CommonOpenFileDialog fb = new CommonOpenFileDialog(); fb.IsFolderPicker = true; fb.Title = "Please select the directory that your project resides in."; fb.EnsurePathExists = true; CommonFileDialogResult rs = fb.ShowDialog(); if (rs == CommonFileDialogResult.Cancel) return; // Get the path. string dir = fb.FileName; // Check if it is empty or if the user clicked Cancel. if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir)) return; // Check if it is a valid project. if (!Directory.Exists(dir + "/Package") || !File.Exists(dir + "/data.sqlite")) { MessageBox.Show("The selected project is not a valid project.", "Repairing Mod Builder project", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Ask if the user wants to generate a new database, or to just add the tables. DialogResult result = MessageBox.Show("Should the existing database be truncated? Answering no will instead try to add all missing data.", "Reparing project", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Cancel) return; // New instance of the mod editor. modEditor me = new modEditor(); // Fiddle with the database. me.generateSQL(dir, (result == DialogResult.Yes), ModParser.parsePackageInfo(dir + "/Package/package-info.xml")); // Do /Source and /Package exist? if (!Directory.Exists(dir + "/Source")) Directory.CreateDirectory(dir + "/Source"); if (!Directory.Exists(dir + "/Package")) Directory.CreateDirectory(dir + "/Package"); // Ask if the user wants to load the project. result = MessageBox.Show("Your project has been repaired. Do you want to load the project now?", "Project repaired", MessageBoxButtons.YesNo, MessageBoxIcon.Question); // Yes? Load the project. if (result == DialogResult.Yes) PackageWorker.bootstrapLoad(dir); /* { // Show a loadProject dialog. loadProject lp = new loadProject(); lp.Show(); // Load the project. bool stat = lp.openProjDir(dir); // Check the status. if (stat == false) MessageBox.Show("An error occured while loading the project.", "Loading project", MessageBoxButtons.OK, MessageBoxIcon.Error); // Close the loadProject dialog. lp.Close(); }*/ }