private void ProcessDFNFile(UOXData.Script.Script myFile, string sName) { // In each section, check for any SCRIPT tags // If we find any, and they're of the format [[x]], replace the x // with the valid script number found in the earlier lookup foreach (UOXData.Script.ScriptSection mSect in myFile.Sections) { UOXData.Script.TagDataPair mPair = mSect.GetDataPair("SCRIPT"); if (mPair != null) { if (mPair.Data.Value.Trim().StartsWith("[[")) { // we have to do the lookup/replacement here ... what fun! string mValue = mPair.Data.Value; int startIdx = mValue.LastIndexOf("["); int endIdx = mValue.IndexOf("]"); int toLookup = UOXData.Conversion.ToInt32(mValue.Substring(startIdx + 1, endIdx - (startIdx + 1))); mPair.Data.Value = pkgConfig.GetTranslatedNumber(toLookup).ToString(); } } } // OK, we've updated our scripts, isn't this wonderful? // Create a new text file with the appropriate name // and then pass the stream to myFile.Save() string dfnPath = pkgConfig.DFNPath + pkgConfig.GetDFNSection(sName.Replace("\\", "/")) + pkgConfig.DirPath; string filePath = GetPath(sName.Replace("\\", "/")); string [] paths = filePath.Split('/'); string buildingPath = dfnPath; if (!Directory.Exists(dfnPath)) { Directory.CreateDirectory(dfnPath); } if (paths.Length > 1) { for (int i = 0; i < paths.Length; ++i) { buildingPath += "/" + paths[i]; if (!Directory.Exists(buildingPath)) { Directory.CreateDirectory(buildingPath); } } } System.IO.StreamWriter ioStream = File.CreateText(buildingPath + GetFile(sName)); myFile.Save(ioStream); ioStream.Flush(); ioStream.Close(); }
private void cmdUOX3IniFind_Click(object sender, System.EventArgs e) { opnFileDialog.Filter = "INI files (*.ini)|*.ini|All files (*.*)|*.*"; if (opnFileDialog.ShowDialog() == DialogResult.OK) { txtUOX3Ini.Text = opnFileDialog.FileName; iniScript = new UOXData.Script.Script(txtUOX3Ini.Text); UOXData.Script.ScriptSection dirSect = iniScript.FindSection("directories"); if (dirSect != null) { dfnPath = dirSect.FindTag("DEFSDIRECTORY"); } else { dfnPath = ""; } } else { txtUOX3Ini.Text = ""; } }
public SetupInfo(UOXData.Script.Script iniScript) { iniFile = iniScript; dfnPath = ""; jsPath = ""; UOXData.Script.ScriptSection dirSect = iniScript.FindSection("directories"); if (dirSect != null) { dfnPath = dirSect.FindTag("DEFSDIRECTORY").Replace("\\", "/"); jsPath = dirSect.FindTag("SCRIPTSDIRECTORY").Replace("\\", "/"); } else { System.Windows.Forms.MessageBox.Show("No definitions directory found!"); return; } configScripts = new UOXData.Script.Script[3]; configScripts[0] = new UOXData.Script.Script(jsPath + "/jse_fileassociations.scp"); configScripts[1] = new UOXData.Script.Script(jsPath + "/jse_objectassociations.scp"); configScripts[2] = new UOXData.Script.Script(jsPath + "/jse_typeassociations.scp"); jsFiles = new System.Collections.Hashtable(); generalSetup = new System.Collections.ArrayList[6]; for (int i = 0; i < 6; ++i) { generalSetup[i] = new System.Collections.ArrayList(); } dfnFiles = new System.Collections.ArrayList[(int)UOXData.Script.DFN_Categories.NUM_DEFS]; for (int i = (int)UOXData.Script.DFN_Categories.FIRST_DEF; i < (int)UOXData.Script.DFN_Categories.NUM_DEFS; ++i) { dfnFiles[i] = new System.Collections.ArrayList(); } inUse = new UOXData.Script.ScriptSection(); }
public void Parse(UOXData.Script.Script stpInfo) { UOXData.Script.ScriptSection mSection = null; mSection = stpInfo.FindSection("DESCRIPTION"); if (mSection != null) { UOXData.Script.TagDataPair t = mSection.GetDataPair("DIRECTORY"); if (t != null) { dirPath = t.Data.Value.Replace("\\", "/"); if (dirPath[dirPath.Length - 1] != '/') { dirPath += "/"; } } else { dirPath = "custom/"; } } else { dirPath = "custom/"; } // parse the individual DFN sections now and store what goes where for (int i = (int)UOXData.Script.DFN_Categories.FIRST_DEF; i < (int)UOXData.Script.DFN_Categories.NUM_DEFS; ++i) { mSection = stpInfo.FindSection(((UOXData.Script.DFN_Categories)i).ToString()); if (mSection != null) { foreach (UOXData.Script.TagDataPair t in mSection.TagDataPairs) { dfnFiles[i].Add(t.Data); } } } // Now let's grab the JS file request stuff, and find some free mappings // so that we can update the config files mSection = stpInfo.FindSection("JS_FILES"); if (mSection != null) { foreach (UOXData.Script.TagDataPair t in mSection.TagDataPairs) { int freeNumber = FindFreeNumber(inUse); if (freeNumber != -1) { jsFiles.Add(t.Tag, freeNumber); inUse.Add(freeNumber.ToString(), t.Data.Value); } } } // OK, we've built up our list of free numbers // Now let's update the relevant config files // with the newly acquired data UOXData.Script.ScriptSection tSection = null; string [] sectTypes = new string[6]; sectTypes[0] = "COMMAND"; sectTypes[1] = "MAGIC"; sectTypes[2] = "CONSOLE"; sectTypes[3] = "PACKET"; sectTypes[4] = "SKILLUSE"; sectTypes[5] = "GENERIC"; mSection = stpInfo.FindSection("CONFIGURE"); if (mSection != null) { for (int i = 0; i < 6; ++i) { UOXData.Script.TagDataPair t = mSection.GetDataPair(sectTypes[i]); if (t != null) { if (i != 5) { tSection = configScripts[0].FindSection(sectTypes + "_SCRIPTS"); } else { tSection = configScripts[0].FindSection("SCRIPT_LIST"); } string[] values = t.Data.Value.Split(','); for (int j = 0; j < values.Length; ++j) { bool containsKey = jsFiles.ContainsKey(values[j].Trim()); if (containsKey) { string tag = ((int)jsFiles[values[j].Trim()]).ToString(); string data = dirPath + inUse.GetDataPair(tag).Data.Value; tSection.Add(tag, data); } } } } } // OK, the file associations config file has been updated // Let's do envoke now // Let's do type now }
private void cmdSelectPackage_Click(object sender, System.EventArgs e) { opnFileDialog.Filter = "Package files (*.zip)|*.zip|All files (*.*)|*.*"; if (opnFileDialog.ShowDialog() == DialogResult.OK) { listPackageFiles.Items.Clear(); setupInfo = null; txtPackageDetails.Text = ""; currentZip = opnFileDialog.FileName; zipFile = new ICSCZL.Zip.ZipFile(currentZip); System.Collections.IEnumerator blah = zipFile.GetEnumerator(); while (blah.MoveNext()) { this.listPackageFiles.Items.Add(blah.Current); ICSCZL.Zip.ZipEntry theEntry = (ICSCZL.Zip.ZipEntry)blah.Current; if (theEntry.Name == "readme.txt") { int size = 2048; byte[] toDisp = new byte[2048]; System.IO.Stream s = zipFile.GetInputStream(theEntry); while (true) { size = s.Read(toDisp, 0, toDisp.Length); if (size > 0) { for (int i = 0; i < size; ++i) { this.txtPackageDetails.Text += (char)toDisp[i]; } } else { break; } } } else if (theEntry.Name == "setup.info") { System.IO.Stream s = zipFile.GetInputStream(theEntry); setupInfo = new UOXData.Script.Script(s); pkgConfig = new SetupInfo(iniScript); pkgConfig.Parse(setupInfo); } } mPackage = new Package(zipFile, pkgConfig); if (setupInfo == null) { System.Windows.Forms.MessageBox.Show("Zip file does not contain a setup.info! Likely an invalid package"); } } else { currentZip = ""; if (zipFile != null) { zipFile = null; } setupInfo = null; } }