public addDeletionInstructionDialog(string workingDirectory, modEditor me, SQLiteConnection conn, int editing)
        {
            InitializeComponent();
            this.workingDirectory = workingDirectory;
            this.me = me;
            this.conn = conn;
            this.editing = editing;

            if (editing != 0)
            {
                string sql = "SELECT file_name, type FROM files_delete WHERE id = " + editing + " LIMIT 1";
                SQLiteCommand command = new SQLiteCommand(sql, conn);
                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    char[] chars = { '/' };
                    string[] pieces = reader["file_name"].ToString().Split(chars, 2);
                    if (pieces.Length == 1)
                        fileName.Text = pieces[0];
                    else if (pieces.Length == 2)
                    {
                        filePrefix.SelectedItem = pieces[0];
                        fileName.Text = pieces[1];
                    }

                    whatIs_Dir.Checked = reader["type"].ToString() == "dir";
                    whatIs_File.Checked = reader["type"].ToString() == "file";
                }
            }
        }
        public addDeletionInstructionDialog(string workingDirectory, modEditor me, SQLiteConnection conn, int editing)
        {
            InitializeComponent();
            this.workingDirectory = workingDirectory;
            this.me      = me;
            this.conn    = conn;
            this.editing = editing;

            if (editing != 0)
            {
                string           sql     = "SELECT file_name, type FROM files_delete WHERE id = " + editing + " LIMIT 1";
                SQLiteCommand    command = new SQLiteCommand(sql, conn);
                SQLiteDataReader reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    char[]   chars  = { '/' };
                    string[] pieces = reader["file_name"].ToString().Split(chars, 2);
                    if (pieces.Length == 1)
                    {
                        fileName.Text = pieces[0];
                    }
                    else if (pieces.Length == 2)
                    {
                        filePrefix.SelectedItem = pieces[0];
                        fileName.Text           = pieces[1];
                    }

                    whatIs_Dir.Checked  = reader["type"].ToString() == "dir";
                    whatIs_File.Checked = reader["type"].ToString() == "file";
                }
            }
        }
        public addExtractionInstructionDialog(string workingDirectory, modEditor me, SQLiteConnection conn, int editing)
        {
            InitializeComponent();
            this.workingDirectory = workingDirectory;
            this.me = me;
            this.conn = conn;
            this.editing = editing;
            fileComboBox.Items.Clear();
            refreshComboboxList(workingDirectory + "\\Source");

            if (editing != 0)
            {
                string sql = "SELECT file_name, destination FROM files WHERE id = " + editing + " LIMIT 1";
                SQLiteCommand command = new SQLiteCommand(sql, conn);
                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    if (reader["destination"].ToString() != "$boarddir" && reader["destination"].ToString() != "$sourcedir" && reader["destination"].ToString() != "$themedir" && reader["destination"].ToString() != "$languagedir" && reader["destination"].ToString() != "$avatardir" && reader["destination"].ToString() != "$imagesdir")
                    {
                        char[] chars = { '/' };
                        string[] pieces = reader["destination"].ToString().Split(chars, 2);
                        filePrefix.SelectedItem = pieces[0];
                        fileName.Text = pieces[1];
                    }
                    else
                        filePrefix.SelectedItem = reader["destination"].ToString();

                    fileComboBox.SelectedItem = reader["file_name"];
                }
            }
        }
        public addExtractionInstructionDialog(string workingDirectory, modEditor me, SQLiteConnection conn, int editing)
        {
            InitializeComponent();
            this.workingDirectory = workingDirectory;
            this.me      = me;
            this.conn    = conn;
            this.editing = editing;
            fileComboBox.Items.Clear();
            refreshComboboxList(workingDirectory + "\\Source");

            if (editing != 0)
            {
                string           sql     = "SELECT file_name, destination FROM files WHERE id = " + editing + " LIMIT 1";
                SQLiteCommand    command = new SQLiteCommand(sql, conn);
                SQLiteDataReader reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    if (reader["destination"].ToString() != "$boarddir" && reader["destination"].ToString() != "$sourcedir" && reader["destination"].ToString() != "$themedir" && reader["destination"].ToString() != "$languagedir" && reader["destination"].ToString() != "$avatardir" && reader["destination"].ToString() != "$imagesdir")
                    {
                        char[]   chars  = { '/' };
                        string[] pieces = reader["destination"].ToString().Split(chars, 2);
                        filePrefix.SelectedItem = pieces[0];
                        fileName.Text           = pieces[1];
                    }
                    else
                    {
                        filePrefix.SelectedItem = reader["destination"].ToString();
                    }

                    fileComboBox.SelectedItem = reader["file_name"];
                }
            }
        }
Example #5
0
        private void openNewProject(object sender, EventArgs e)
        {
            // Start a new instance of the Mod Editor.
            modEditor me = new modEditor();

            // Some default values.
            me.genPkgID.Checked          = true;
            me.includeModManLine.Checked = true;

            me.authorName.Text = Properties.Settings.Default.idUsername;

            // Show the instance.
            me.Show();
        }
Example #6
0
        // Loads and sets up the environment.
        public addInstruction(string workingDirectory, SQLiteConnection conn, int editing, modEditor mode)
        {
            // Start the form.
            InitializeComponent();

            // Set the working directory.
            wD = workingDirectory;

            // And set the SQLite connection.
            co = conn;

            // ModEditor form
            me = mode;

            // Are we editing anything?
            if (editing != 0)
            {
                // Yes we are... Set up the query.
                string sql = "SELECT before, after, type, file, optional FROM instructions WHERE id = " + editing + " LIMIT 1";

                // Execute it.
                SQLiteCommand    command = new SQLiteCommand(sql, co);
                SQLiteDataReader reader  = command.ExecuteReader();

                // And read and insert the data.
                while (reader.Read())
                {
                    before.Text = (string)reader["before"];
                    after.Text  = (string)reader["after"];

                    char[]   chars  = { '/' };
                    string[] pieces = reader["file"].ToString().Split(chars, 2);
                    filePrefix.SelectedItem = pieces[0];
                    fileEdited.Text         = pieces[1];

                    // Gather and set the method.
                    switch ((string)reader["type"])
                    {
                    case "add_before":
                        method.SelectedItem = "Add before";
                        break;

                    case "add_after":
                        method.SelectedItem = "Add after";
                        break;

                    case "end":
                        method.SelectedItem = "At the end of file";
                        break;

                    default:
                        method.SelectedItem = "Replace";
                        break;
                    }

                    // Check for an optional operation.
                    if (Convert.ToInt32(reader["optional"]) == 1)
                    {
                        optionalCheck.Checked = true;
                    }
                }
                this.editing = editing;
            }
        }
Example #7
0
        private void okButton_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(packageInputPath.Text))
            {
                MessageBox.Show("Your input directory does not exist. Please select a different one.", "Convert Project", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!Directory.Exists(outputDirectory.Text))
                Directory.CreateDirectory(outputDirectory.Text);

            // Make sure the user knows we're busy...
            System.Threading.Thread.Sleep(100);
            cvWorking.Visible = true;

            modEditor me = new modEditor();
            Dictionary<string, string> details = Classes.ModParser.parsePackageInfo(packageInfoXMLPath.Text);
            me.generateSQL(outputDirectory.Text, true, details);

            // Update a setting.
            string updatesql = "UPDATE settings SET value = \"false\" WHERE key = \"autoGenerateModID\"";
            SQLiteCommand ucomm = new SQLiteCommand(updatesql, me.conn);
            ucomm.ExecuteNonQuery();

            // Create a readme.txt if the text is inline.
            bool readmeTextInline = (readmeTXTPath.Text == "Inline");

            // Parse the XML.
            #region Read the install.xml, if it exists.
            if (File.Exists(installXmlPath.Text))
            {
                XmlTextReader xmldoc = new XmlTextReader(installXmlPath.Text);
                xmldoc.DtdProcessing = DtdProcessing.Ignore;
                string currfile = "";
                string sql = "INSERT INTO instructions(id, before, after, type, file, optional) VALUES(null, @beforeText, @afterText, @type, @fileEdited, @optional)";

                while (xmldoc.Read())
                {
                    if (xmldoc.NodeType.Equals(XmlNodeType.Element))
                    {
                        switch (xmldoc.LocalName)
                        {
                            case "file":
                                currfile = xmldoc.GetAttribute("name");
                                break;

                            case "operation":
                                SQLiteCommand command = new SQLiteCommand(sql, me.conn);
                                command.Parameters.AddWithValue("@fileEdited", currfile);
                                command.Parameters.AddWithValue("@optional", (xmldoc.GetAttribute("error") == "skip"));

                                xmldoc.ReadToDescendant("search");
                                command.Parameters.AddWithValue("@type", xmldoc.GetAttribute("position"));
                                command.Parameters.AddWithValue("@beforeText", xmldoc.ReadElementContentAsString().Replace("\r", "\n").Replace("\n", "\r\n"));

                                xmldoc.ReadToNextSibling("add");
                                command.Parameters.AddWithValue("@afterText", xmldoc.ReadElementContentAsString().Replace("\r", "\n").Replace("\n", "\r\n"));

                                command.ExecuteNonQuery();
                                break;
                        }
                    }
                }
            }
            #endregion

            // Copy over any remaining files.
            Dictionary<string, string> pfiles = new Dictionary<string, string>();
            Directory.CreateDirectory(outputDirectory.Text + "/Package");
            Directory.CreateDirectory(outputDirectory.Text + "/Source");

            pfiles.Add("Package/package-info.xml", packageInfoXMLPath.Text);
            if (!string.IsNullOrEmpty(readmeTXTPath.Text))
                pfiles.Add("Package/readme.txt", readmeTXTPath.Text);
            if (!string.IsNullOrEmpty(installPHPPath.Text))
                pfiles.Add("Package/install.php", installPHPPath.Text);
            if (!string.IsNullOrEmpty(uninstallPHPPath.Text))
                pfiles.Add("Package/uninstall.php", uninstallPHPPath.Text);
            if (!string.IsNullOrEmpty(installDatabasePHPPath.Text))
                pfiles.Add("Package/installDatabase.php", installDatabasePHPPath.Text);
            if (!string.IsNullOrEmpty(uninstallDatabasePHPPath.Text))
                pfiles.Add("Package/uninstallDatabase.php", uninstallDatabasePHPPath.Text);

            foreach (var pair in pfiles)
            {
                if (!File.Exists(pair.Value))
                    continue;

                if (File.Exists(outputDirectory.Text + "/" + pair.Key))
                    File.Delete(outputDirectory.Text + "/" + pair.Key);

                File.Copy(pair.Value, outputDirectory.Text + "/" + pair.Key);
            }

            #region Read the package.xml, if it exists, for any further information.

            if (File.Exists(packageInfoXMLPath.Text))
            {
                XmlDocument l_document = new XmlDocument();
                l_document.Load(packageInfoXMLPath.Text);

                SQLiteCommand sql;
                string sqlquery;
                foreach (XmlNode l_packageNode in l_document.LastChild.ChildNodes)
                {
                    Console.WriteLine("Test node name: " + l_packageNode.Name);
                    if (l_packageNode.Name == "install")
                    {
                        foreach (XmlNode l_operationNode in l_packageNode.ChildNodes)
                        {
                            Console.WriteLine("Test child node name: " + l_operationNode.Name);
                            switch (l_operationNode.Name)
                            {
                                case "readme":
                                    if (readmeTextInline)
                                        File.WriteAllText(outputDirectory.Text + "/Package/readme.txt", l_operationNode.InnerText.Replace("\r", "\n").Replace("\n", "\r\n"));
                                    break;
                                case "require-file":
                                     Console.WriteLine("File name: " + l_operationNode.Attributes["name"].Value);
                                     Console.WriteLine("Destination: " + l_operationNode.Attributes["destination"].Value);
                                     string[] pieces = l_operationNode.Attributes["name"].Value.Split('/');
                                     string lastpiece = pieces[pieces.Length - 1];

                                     if (!Directory.Exists(outputDirectory.Text + "/Source/" + l_operationNode.Attributes["name"].Value.Replace("/" + lastpiece, "")) && l_operationNode.Attributes["name"].Value != lastpiece)
                                         Directory.CreateDirectory(outputDirectory.Text + "/Source/" + l_operationNode.Attributes["name"].Value.Replace("/" + lastpiece, ""));

                                     File.Copy(packageInputPath.Text + "/" + l_operationNode.Attributes["name"].Value, outputDirectory.Text + "/Source/" + l_operationNode.Attributes["name"].Value, true);
                                     Console.WriteLine("Copied file");

                                    // Set up a query.
                                     sqlquery = "INSERT INTO files(id, file_name, destination) VALUES(null, @fileName, @destination)";
                                     sql = new SQLiteCommand(sqlquery, me.conn);

                                     sql.Parameters.AddWithValue("@fileName", l_operationNode.Attributes["name"].Value);
                                     sql.Parameters.AddWithValue("@destination", l_operationNode.Attributes["destination"].Value);

                                     sql.ExecuteNonQuery();

                                     break;
                                case "require-dir":
                                    // Just copy over the dir.
                                     DirectoryCopy(packageInputPath.Text + "/" + l_operationNode.Attributes["name"].Value, outputDirectory.Text + "/Source/" + l_operationNode.Attributes["name"].Value, true);

                                     // Set up a query.
                                     sqlquery = "INSERT INTO files(id, file_name, destination) VALUES(null, @fileName, @destination)";
                                     sql = new SQLiteCommand(sqlquery, me.conn);

                                     sql.Parameters.AddWithValue("@fileName", l_operationNode.Attributes["name"].Value);
                                     sql.Parameters.AddWithValue("@destination", l_operationNode.Attributes["destination"].Value);

                                     sql.ExecuteNonQuery();
                                    break;
                            }
                        }
                    }
                    if (l_packageNode.Name == "uninstall")
                    {
                        foreach (XmlNode l_operationNode in l_packageNode.ChildNodes)
                        {
                            switch (l_operationNode.Name)
                            {
                                case "remove-file":
                                    sqlquery = "INSERT INTO files_delete(id, file_name, type) VALUES(null, @fileName, @type)";
                                    sql = new SQLiteCommand(sqlquery, me.conn);
                                    sql.Parameters.AddWithValue("@fileName", l_operationNode.Attributes["name"].Value);
                                    sql.Parameters.AddWithValue("@type", "file");
                                    sql.ExecuteNonQuery();
                                    break;

                                case "remove-dir":
                                    sqlquery = "INSERT INTO files_delete(id, file_name, type) VALUES(null, @fileName, @type)";
                                    sql = new SQLiteCommand(sqlquery, me.conn);
                                    sql.Parameters.AddWithValue("@fileName", l_operationNode.Attributes["name"].Value);
                                    sql.Parameters.AddWithValue("@type", "dir");
                                    sql.ExecuteNonQuery();
                                    break;
                            }
                        }
                    }
                }
            }
            #endregion

            me.Close();

            DialogResult result = MessageBox.Show("The package has been converted, do you want to load it now?", "Converting Project", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
                ModBuilder.Classes.PackageWorker.bootstrapLoad(outputDirectory.Text);
            Close();
        }
Example #8
0
        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();
             * }*/
        }
Example #9
0
        private void okButton_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(packageInputPath.Text))
            {
                MessageBox.Show("Your input directory does not exist. Please select a different one.", "Convert Project", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!Directory.Exists(outputDirectory.Text))
            {
                Directory.CreateDirectory(outputDirectory.Text);
            }

            // Make sure the user knows we're busy...
            System.Threading.Thread.Sleep(100);
            cvWorking.Visible = true;

            modEditor me = new modEditor();
            Dictionary <string, string> details = Classes.ModParser.parsePackageInfo(packageInfoXMLPath.Text);

            me.generateSQL(outputDirectory.Text, true, details);

            // Update a setting.
            string        updatesql = "UPDATE settings SET value = \"false\" WHERE key = \"autoGenerateModID\"";
            SQLiteCommand ucomm     = new SQLiteCommand(updatesql, me.conn);

            ucomm.ExecuteNonQuery();

            // Create a readme.txt if the text is inline.
            bool readmeTextInline = (readmeTXTPath.Text == "Inline");

            // Parse the XML.
            #region Read the install.xml, if it exists.
            if (File.Exists(installXmlPath.Text))
            {
                XmlTextReader xmldoc = new XmlTextReader(installXmlPath.Text);
                xmldoc.DtdProcessing = DtdProcessing.Ignore;
                string currfile = "";
                string sql      = "INSERT INTO instructions(id, before, after, type, file, optional) VALUES(null, @beforeText, @afterText, @type, @fileEdited, @optional)";

                while (xmldoc.Read())
                {
                    if (xmldoc.NodeType.Equals(XmlNodeType.Element))
                    {
                        switch (xmldoc.LocalName)
                        {
                        case "file":
                            currfile = xmldoc.GetAttribute("name");
                            break;

                        case "operation":
                            SQLiteCommand command = new SQLiteCommand(sql, me.conn);
                            command.Parameters.AddWithValue("@fileEdited", currfile);
                            command.Parameters.AddWithValue("@optional", (xmldoc.GetAttribute("error") == "skip"));

                            xmldoc.ReadToDescendant("search");
                            command.Parameters.AddWithValue("@type", xmldoc.GetAttribute("position"));
                            command.Parameters.AddWithValue("@beforeText", xmldoc.ReadElementContentAsString().Replace("\r", "\n").Replace("\n", "\r\n"));

                            xmldoc.ReadToNextSibling("add");
                            command.Parameters.AddWithValue("@afterText", xmldoc.ReadElementContentAsString().Replace("\r", "\n").Replace("\n", "\r\n"));

                            command.ExecuteNonQuery();
                            break;
                        }
                    }
                }
            }
            #endregion

            // Copy over any remaining files.
            Dictionary <string, string> pfiles = new Dictionary <string, string>();
            Directory.CreateDirectory(outputDirectory.Text + "/Package");
            Directory.CreateDirectory(outputDirectory.Text + "/Source");

            pfiles.Add("Package/package-info.xml", packageInfoXMLPath.Text);
            if (!string.IsNullOrEmpty(readmeTXTPath.Text))
            {
                pfiles.Add("Package/readme.txt", readmeTXTPath.Text);
            }
            if (!string.IsNullOrEmpty(installPHPPath.Text))
            {
                pfiles.Add("Package/install.php", installPHPPath.Text);
            }
            if (!string.IsNullOrEmpty(uninstallPHPPath.Text))
            {
                pfiles.Add("Package/uninstall.php", uninstallPHPPath.Text);
            }
            if (!string.IsNullOrEmpty(installDatabasePHPPath.Text))
            {
                pfiles.Add("Package/installDatabase.php", installDatabasePHPPath.Text);
            }
            if (!string.IsNullOrEmpty(uninstallDatabasePHPPath.Text))
            {
                pfiles.Add("Package/uninstallDatabase.php", uninstallDatabasePHPPath.Text);
            }

            foreach (var pair in pfiles)
            {
                if (!File.Exists(pair.Value))
                {
                    continue;
                }

                if (File.Exists(outputDirectory.Text + "/" + pair.Key))
                {
                    File.Delete(outputDirectory.Text + "/" + pair.Key);
                }

                File.Copy(pair.Value, outputDirectory.Text + "/" + pair.Key);
            }

            #region Read the package.xml, if it exists, for any further information.

            if (File.Exists(packageInfoXMLPath.Text))
            {
                XmlDocument l_document = new XmlDocument();
                l_document.Load(packageInfoXMLPath.Text);

                SQLiteCommand sql;
                string        sqlquery;
                foreach (XmlNode l_packageNode in l_document.LastChild.ChildNodes)
                {
                    Console.WriteLine("Test node name: " + l_packageNode.Name);
                    if (l_packageNode.Name == "install")
                    {
                        foreach (XmlNode l_operationNode in l_packageNode.ChildNodes)
                        {
                            Console.WriteLine("Test child node name: " + l_operationNode.Name);
                            switch (l_operationNode.Name)
                            {
                            case "readme":
                                if (readmeTextInline)
                                {
                                    File.WriteAllText(outputDirectory.Text + "/Package/readme.txt", l_operationNode.InnerText.Replace("\r", "\n").Replace("\n", "\r\n"));
                                }
                                break;

                            case "require-file":
                                Console.WriteLine("File name: " + l_operationNode.Attributes["name"].Value);
                                Console.WriteLine("Destination: " + l_operationNode.Attributes["destination"].Value);
                                string[] pieces    = l_operationNode.Attributes["name"].Value.Split('/');
                                string   lastpiece = pieces[pieces.Length - 1];

                                if (!Directory.Exists(outputDirectory.Text + "/Source/" + l_operationNode.Attributes["name"].Value.Replace("/" + lastpiece, "")) && l_operationNode.Attributes["name"].Value != lastpiece)
                                {
                                    Directory.CreateDirectory(outputDirectory.Text + "/Source/" + l_operationNode.Attributes["name"].Value.Replace("/" + lastpiece, ""));
                                }

                                File.Copy(packageInputPath.Text + "/" + l_operationNode.Attributes["name"].Value, outputDirectory.Text + "/Source/" + l_operationNode.Attributes["name"].Value, true);
                                Console.WriteLine("Copied file");

                                // Set up a query.
                                sqlquery = "INSERT INTO files(id, file_name, destination) VALUES(null, @fileName, @destination)";
                                sql      = new SQLiteCommand(sqlquery, me.conn);

                                sql.Parameters.AddWithValue("@fileName", l_operationNode.Attributes["name"].Value);
                                sql.Parameters.AddWithValue("@destination", l_operationNode.Attributes["destination"].Value);

                                sql.ExecuteNonQuery();

                                break;

                            case "require-dir":
                                // Just copy over the dir.
                                DirectoryCopy(packageInputPath.Text + "/" + l_operationNode.Attributes["name"].Value, outputDirectory.Text + "/Source/" + l_operationNode.Attributes["name"].Value, true);

                                // Set up a query.
                                sqlquery = "INSERT INTO files(id, file_name, destination) VALUES(null, @fileName, @destination)";
                                sql      = new SQLiteCommand(sqlquery, me.conn);

                                sql.Parameters.AddWithValue("@fileName", l_operationNode.Attributes["name"].Value);
                                sql.Parameters.AddWithValue("@destination", l_operationNode.Attributes["destination"].Value);

                                sql.ExecuteNonQuery();
                                break;
                            }
                        }
                    }
                    if (l_packageNode.Name == "uninstall")
                    {
                        foreach (XmlNode l_operationNode in l_packageNode.ChildNodes)
                        {
                            switch (l_operationNode.Name)
                            {
                            case "remove-file":
                                sqlquery = "INSERT INTO files_delete(id, file_name, type) VALUES(null, @fileName, @type)";
                                sql      = new SQLiteCommand(sqlquery, me.conn);
                                sql.Parameters.AddWithValue("@fileName", l_operationNode.Attributes["name"].Value);
                                sql.Parameters.AddWithValue("@type", "file");
                                sql.ExecuteNonQuery();
                                break;

                            case "remove-dir":
                                sqlquery = "INSERT INTO files_delete(id, file_name, type) VALUES(null, @fileName, @type)";
                                sql      = new SQLiteCommand(sqlquery, me.conn);
                                sql.Parameters.AddWithValue("@fileName", l_operationNode.Attributes["name"].Value);
                                sql.Parameters.AddWithValue("@type", "dir");
                                sql.ExecuteNonQuery();
                                break;
                            }
                        }
                    }
                }
            }
            #endregion

            me.Close();

            DialogResult result = MessageBox.Show("The package has been converted, do you want to load it now?", "Converting Project", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                ModBuilder.Classes.PackageWorker.bootstrapLoad(outputDirectory.Text);
            }
            Close();
        }
Example #10
0
        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);
            }
        }