/// <exception cref="CopeException">Can't open the file as RelicChunky!</exception> public RelicChunkyViewer(UniFile file) : this() { var rcf = new RelicChunkyFile(file); try { rcf.ReadData(); } catch (Exception ex) { throw new CopeException(ex, "Can't open the file as RelicChunky!"); } file.Close(); m_rcf = rcf; _trv_chunks.Nodes.Clear(); foreach (RelicChunk chunk in m_rcf.Chunks) { var tnC = new TreeNode(); string tnName = chunk.ChunkHeader.TypeString + chunk.ChunkHeader.Signature; tnC.Name = tnName; tnC.Text = tnName; chunk.Tag = tnC; tnC.Tag = chunk; if (chunk is FoldChunk) GetChunks(tnC, (FoldChunk)chunk); _trv_chunks.Nodes.Add(tnC); } }
/// <summary> /// Creates a UniFile based on the information from this FSNodeFile. /// </summary> /// <param name="onlyVirtual">Set to true to only return a UniFile if this file is virtual (otherwise null).</param> /// <param name="onlyLocal">Set to true to only return a UniFile if this file is local (otherwise null).</param> /// <returns></returns> public virtual UniFile GetUniFile(bool onlyVirtual = false, bool onlyLocal = false) { if (onlyVirtual) { return(null); } UniFile uniFile = null; try { // try to open it uniFile = new UniFile(GetPath()); } catch (Exception e) { UIHelper.ShowError( "An error occured while trying to load the file! Please ensure that it still exists! Info: {0}", e.Message); if (uniFile != null) { uniFile.Close(); } LoggingManager.HandleException(e); } return(uniFile); }
/// <exception cref="CopeException">Can't open the file as RelicChunky!</exception> public RelicChunkyViewer(UniFile file) : this() { var rcf = new RelicChunkyFile(file); try { rcf.ReadData(); } catch (Exception ex) { throw new CopeException(ex, "Can't open the file as RelicChunky!"); } file.Close(); m_rcf = rcf; _trv_chunks.Nodes.Clear(); foreach (RelicChunk chunk in m_rcf.Chunks) { var tnC = new TreeNode(); string tnName = chunk.ChunkHeader.TypeString + chunk.ChunkHeader.Signature; tnC.Name = tnName; tnC.Text = tnName; chunk.Tag = tnC; tnC.Tag = chunk; if (chunk is FoldChunk) { GetChunks(tnC, (FoldChunk)chunk); } _trv_chunks.Nodes.Add(tnC); } }
private void OpenFile(UniFile file) { m_file = file; try { if (file.FileExtension.ToLowerInvariant() == "dds") { m_image = new FreeImageBitmap(file.Stream, FREE_IMAGE_FORMAT.FIF_DDS); m_format = FREE_IMAGE_FORMAT.FIF_DDS; } else if (file.FileExtension.ToLowerInvariant() == "tga") { m_image = new FreeImageBitmap(file.Stream, FREE_IMAGE_FORMAT.FIF_TARGA); m_format = FREE_IMAGE_FORMAT.FIF_TARGA; } m_picbxImage.Image = (Bitmap)m_image; m_binary = new MemoryStream(); file.Stream.Position = 0; file.Stream.CopyTo(m_binary); } catch (Exception e) { UIHelper.ShowError("Failed to open image! Error: " + e.Message); ModTool.Core.LoggingManager.SendMessage("Failed to open image " + file.FilePath); ModTool.Core.LoggingManager.HandleException(e); } finally { file.Close(); } }
public override bool Close() { if (m_file != null) { m_file.Close(); } return(true); }
public void Close() { if (uFile != null) { if (uFile.IsFileOpen) { uFile.Close(); } } }
/// <exception cref="CopeDoW2Exception">Failed to load file as RBF! Visit the options and ensure that the settings correspond to the game version you're trying to modify.</exception> protected void LoadFile(UniFile file) { if (file.FileExtension == "rbf") { m_rbf = new RelicBinaryFile(file) { KeyProvider = ModManager.RBFKeyProvider, UseKeyProvider = RBFSettings.UseKeyProviderForLoading }; try { m_rbf.ReadData(); } catch (Exception ex) { throw new CopeDoW2Exception(ex, "Failed to load file as RBF! Visit the plugin's options " + "and ensure that the settings correspond to " + "the game version you're trying to modify."); } } else if (file.FileExtension == "attr_pc") { try { var attribStruct = BAFReader.Read(file.Stream); file.Close(); m_rbf = new RelicBinaryFile(attribStruct) { FilePath = file.FilePath, UseKeyProvider = false }; } catch (Exception ex) { throw new CopeDoW2Exception(ex, "Failed to load file as attr_pc!"); } } file.Close(); m_rbfEditorCore.Analyze(m_rbf.AttributeStructure.Root); }
/// <summary> /// Returns a UniFile based on the information from this FSNodeVirtualFile. It will first search for a local file and if there's no local file it'll get the virtual file. /// </summary> /// <param name="onlyVirtual">Set to true to ignore local files.</param> /// <param name="onlyLocal">Set to true to ignore virtual files.</param> /// <returns></returns> public override UniFile GetUniFile(bool onlyVirtual = false, bool onlyLocal = false) { UniFile uniFile = null; if (!onlyVirtual && HasLocal) { try { // try to open it uniFile = new UniFile(GetPath()); } catch (Exception e) { UIHelper.ShowError( "An error occured while trying to load the file! Please ensure that it still exists! Info: {0}", e.Message); if (uniFile != null) { uniFile.Close(); } LoggingManager.HandleException(e); } return(uniFile); } // is it stored in a SGA archive? if (!onlyLocal || !HasLocal) { SGAStoredFile sgasfExtract = VirtualFile; try { // try to extract that file for our use into RAM uniFile = new UniFile(sgasfExtract.SGA.ExtractFile(sgasfExtract, (sgasfExtract.SGA.Stream))); } catch (Exception e) { UIHelper.ShowError( "An error occured while trying to load the file! Please ensure that it's SGA archive still exists! Info: {0}", e.Message); if (uniFile != null) { uniFile.Close(); } LoggingManager.HandleException(e); } // set a pseudo path that will be used when saving the file if (uniFile != null) { uniFile.FilePath = GetPath(); } } return(uniFile); }
private static void DragDropGeneral(DragEventArgs e) { if (e.Effect == DragDropEffects.Move) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var fileNames = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string s in fileNames) { // only one SGA / module at a time (currently)! if (s.EndsWith(".sga")) { if (ModManager.IsAnythingLoaded && UIHelper.ShowYNQuestion("Warning!", "Opening a SGA archive will close all other archives and tabs!") == DialogResult.No) { return; } ModManager.LoadSGAFile(s); return; } if (s.EndsWith(".module")) { if (ModManager.IsAnythingLoaded && UIHelper.ShowYNQuestion("Warning!", "Opening another module will close the current mod with all it's tabs and SGAs! Continue anyway?") == DialogResult.No) { return; } ModManager.LoadModule(s); return; } var tmp = new UniFile(s); try { FileManager.LoadFile(tmp); } catch (Exception ex) { tmp.Close(); UIHelper.ShowError(ex.Message); return; } } } } }
public override bool Close() { if (m_file != null) { m_file.Close(); } if (m_picbxImage.Image != null) { m_picbxImage.Image.Dispose(); m_picbxImage.Image = null; } if (m_binary != null) { m_binary.Close(); m_binary.Dispose(); } m_picbxImage.Dispose(); if (m_image != null) { m_image.Dispose(); } return(true); }
static void Main(string[] args) { bool debug = Properties.Settings.Default.Verbose; U2Conn srcConn = new U2Conn(); SqlConn destConn = new SqlConn(); srcConn.Host = Properties.Settings.Default.U2Host; // "pmsteel.kwyk.net"; srcConn.Login = Properties.Settings.Default.U2Login; // "administrator"; srcConn.Password = Properties.Settings.Default.U2Password; // "H!carb0n"; srcConn.Catalog = Properties.Settings.Default.U2Account; // "C:\\BAI.PROD\\PM"; destConn.Host = Properties.Settings.Default.SqlHost; // "pmsteel.kwyk.net"; destConn.Login = Properties.Settings.Default.SqlLogin; // "pmsteel"; destConn.Password = Properties.Settings.Default.SqlPassword; // "H!carb0n"; destConn.Catalog = Properties.Settings.Default.SqlDatabase; // "pmsteel" /* try { srcConn.Connect(); destConn.Connect(); srcConn.Disconnect(); destConn.Disconnect(); } catch (Exception e) { debugPrint(true, "Error: " + e); } */ String sqlStmt = ""; try { // every thing runs out of the UniSession instance. UniSession uSession = null; //Set up variables. uSession = UniObjects.OpenSession(Properties.Settings.Default.U2Host, Properties.Settings.Default.U2Login, Properties.Settings.Default.U2Password, Properties.Settings.Default.U2Account); debugPrint(debug, "U2 openSession succeeded\n"); debugPrint(debug, "Status = " + uSession.Status + "\n"); //Class.forName("net.sourceforge.jtds.jdbc.Driver"); //Connection conn = DriverManager.getConnection(sqlJdbcUrl, sqlUser, sqlPass); //debugPrint(debug, "SQL Server connection succeeded"); //Statement stmt = conn.createStatement(); UniFile uf = uSession.CreateUniFile(Properties.Settings.Default.U2File); debugPrint(debug, Properties.Settings.Default.U2File + " file opened\n"); //debugPrint(debug, uf.ToString()); UniSelectList usl = uSession.CreateUniSelectList(8); StreamWriter sw = new StreamWriter(@"c:\temp\u2rl.xml"); usl.Select(uf); while (!usl.LastRecordRead) { String key = usl.Next(); debugPrint(debug, "key: " + key + "\n"); if (key != "") { XElement xd = new XElement("data"); XElement xd2 = new XElement("data"); UniDynArray udaRow = uf.Read(key); int v2 = 0; int s2 = 1; while (s2 > 0) { XElement xv2 = new XElement("val", new XAttribute("loc", s2)); s2 = 0; for (int f2 = 1; f2 <= udaRow.Dcount(); f2++) { if ( s2 <= udaRow.Dcount(f, v)) { XElement xf2 = new XElement("fld", new XAttribute("loc", f2)); string fld = udaRow.Extract(f2, v2).ToString(); if ("" != fld) { } } } for (int f = 1; f <= udaRow.Dcount(); f++) { XElement xf = new XElement("fld", new XAttribute("loc", f)); string fld = udaRow.Extract(f).ToString(); if ("" != fld) { for (int v = 1; v <= udaRow.Dcount(f); v++) { XElement xv = new XElement("val", new XAttribute("loc", v)); string val = udaRow.Extract(f, v).ToString(); if ("" != val) { for (int s = 1; s <= udaRow.Dcount(f, v); s++) { xv.Add(new XElement("sub", new XAttribute("loc", s), udaRow.Extract(f, v, s).ToString())); } } xf.Add(xv); } } xd.Add(xf); } XElement xr = new XElement("row", new XElement("id", key), xd); sqlStmt = "INSERT INVF(u2_id, u2_data) VALUES ('" + key.Replace("'", "''") + "', '" + xd.ToString().Replace("'", "''") + "')"; sw.WriteLine(xr); } } sw.Close(); //UniDynArray udaRow = uSession.CreateUniDynArray(usl.Next()); //debugPrint(debug, usl.readList().ToString()); //while (!usl.IsLastRecordRead) //while (null != udaRow) //{ //String usKey = udaRow.Extract(1).ToString(); //Properties.Settings.Default.SqlTable = usKey; //debugPrint(debug, "key: " + usKey + "\n"); //debugPrint(debug, usKey.ToString() + ": " + Properties.Settings.Default.SqlTable); //sqlStmt = "IF EXISTS (SELECT * FROM sys.tables WHERE OBJECT_ID('dbo.[" + Properties.Settings.Default.SqlTable + "]') IS NOT NULL) DROP TABLE dbo.[" + Properties.Settings.Default.SqlTable + "]"; //debugPrint(debug, sqlStmt); //stmt.executeUpdate(sqlStmt); //sqlStmt = "CREATE TABLE dbo.[" + Properties.Settings.Default.SqlTable + "] (ID varchar(255) NOT NULL,LOC smallint NOT NULL,SEQ smallint NOT NULL,VAL varchar(8000) NOT NULL)"; //debugPrint(debug, sqlStmt); //stmt.executeUpdate(sqlStmt); //{{ int valIdx = 1; int fldIdx = 1; //for (int fldIdx = 1; fldIdx <= udaRow.Dcount(); fldIdx++) //{ // debugPrint(debug, "field: " + udaRow.Extract(fldIdx).ToString()); // for (int valIdx = 1; valIdx <= udaRow.dcount(fldIdx); valIdx++) // { // UniString usValue = udaRow.extract(fldIdx, valIdx); // debugPrint(debug, usValue.ToString()); // } //} //UniFile ufTblFile = uSession.open(usKey); //debugPrint(debug, "file opened"); ////debugPrint(debug, usKey.ToString()); //UniSelectList uslTblList = uSession.selectList(2); //uslTblList.select(ufTblFile); //UniString usTblKey = uslTblList.next(); //int cnt = 0; //while (!uslTblList.isLastRecordRead()) //{ // if (cnt++ % 1000 == 0) debugPrint(debug, "rows: " + cnt); // //debugPrint(debug, usTblKey.ToString()); // UniDynArray udaTblRow = new UniDynArray(ufTblFile.read(usTblKey)); // for (int fldTblIdx = 1; fldTblIdx <= udaTblRow.dcount(); fldTblIdx++) // { // for (int valTblIdx = 1; valTblIdx <= udaTblRow.dcount(fldTblIdx); valTblIdx++) // { // UniString usTblValue = udaTblRow.extract(fldTblIdx, valTblIdx); // //debugPrint(debug, usTblValue.ToString()); // sqlStmt = "INSERT [" + Properties.Settings.Default.SqlTable + "] VALUES ('" + usTblKey.ToString().replace("'", "''") + "', " + fldTblIdx + ", " + valTblIdx + ", '" + usTblValue.ToString().replace("'", "''") + "')"; // //debugPrint(debug, sqlStmt); // //stmt.executeUpdate(sqlStmt); // } // } // usTblKey = uslTblList.next(); //} //udaRow = uSession.CreateUniDynArray(usl.Next()); //} /* udaKeys = usl.readList(); //UniDynArray udaValues; sqlStmt = "TRUNCATE TABLE [" + Properties.Settings.Default.SqlTable + ']'; debugPrint(debug, sqlStmt); stmt.executeUpdate(sqlStmt); for (int keyIdx = 1;keyIdx < udaKeys.count();keyIdx++) { usKey = udaKeys.extract(keyIdx); debugPrint(debug, usKey.ToString()); if (usKey.length() > 0) { debugPrint(debug, udaKeys.count() + " " + usKey + usKey.length() + " " + keyIdx); sqlStmt = "INSERT [" + Properties.Settings.Default.SqlTable + "] VALUES ('" + usKey + "', 0, 1, '" + usKey + "')"; debugPrint(debug, sqlStmt); stmt.executeUpdate(sqlStmt); udaRow = new UniDynArray(uf.read(usKey)); for (int fldIdx = 1; fldIdx <= udaRow.dcount(); fldIdx++) { //usField = udaRow.extract(fldIdx) ; //udaValues = new UniDynArray(usField); for (int valIdx = 1; valIdx <= udaRow.dcount(fldIdx); valIdx++) { usValue = udaRow.extract(fldIdx, valIdx) ; if (usValue.length() > 0) { //debugPrint(debug, fldIdx + " " + valIdx + " -->" + usValue + "<--"); sqlStmt = "INSERT [" + Properties.Settings.Default.SqlTable+ "] VALUES ('" + usKey + "', " + fldIdx + ", " + valIdx + ", '" + usValue.ToString().replace("'", "''") + "')"; debugPrint(debug, sqlStmt); stmt.executeUpdate(sqlStmt); } } } } //debugPrint(debug, udaKeys.extract(keyIdx)); } */ uf.Close(); debugPrint(debug, Properties.Settings.Default.U2File + " file closed\n"); // did we connect? debugPrint(debug, "U2 Disconnected\n"); //conn.close(); //debugPrint(debug, "SQL Disconnected."); } catch (UniSessionException e) { debugPrint(debug, "Error: " + e); } catch (UniFileException e) { debugPrint(debug, "File Error: " + e); } catch (UniSelectListException e) { // TODO Auto-generated catch block debugPrint(debug, "File Error: " + e); } Console.ReadKey(); }
/// <summary> /// Creates a UniFile based on the information from this FSNodeFile. /// </summary> /// <param name="onlyVirtual">Set to true to only return a UniFile if this file is virtual (otherwise null).</param> /// <param name="onlyLocal">Set to true to only return a UniFile if this file is local (otherwise null).</param> /// <returns></returns> public virtual UniFile GetUniFile(bool onlyVirtual = false, bool onlyLocal = false) { if (onlyVirtual) return null; UniFile uniFile = null; try { // try to open it uniFile = new UniFile(GetPath()); } catch (Exception e) { UIHelper.ShowError( "An error occured while trying to load the file! Please ensure that it still exists! Info: {0}", e.Message); if (uniFile != null) uniFile.Close(); LoggingManager.HandleException(e); } return uniFile; }
/// <summary> /// Returns a UniFile based on the information from this FSNodeVirtualFile. It will first search for a local file and if there's no local file it'll get the virtual file. /// </summary> /// <param name="onlyVirtual">Set to true to ignore local files.</param> /// <param name="onlyLocal">Set to true to ignore virtual files.</param> /// <returns></returns> public override UniFile GetUniFile(bool onlyVirtual = false, bool onlyLocal = false) { UniFile uniFile = null; if (!onlyVirtual && HasLocal) { try { // try to open it uniFile = new UniFile(GetPath()); } catch (Exception e) { UIHelper.ShowError( "An error occured while trying to load the file! Please ensure that it still exists! Info: {0}", e.Message); if (uniFile != null) uniFile.Close(); LoggingManager.HandleException(e); } return uniFile; } // is it stored in a SGA archive? if (!onlyLocal || !HasLocal) { SGAStoredFile sgasfExtract = VirtualFile; try { // try to extract that file for our use into RAM uniFile = new UniFile(sgasfExtract.SGA.ExtractFile(sgasfExtract, (sgasfExtract.SGA.Stream))); } catch (Exception e) { UIHelper.ShowError( "An error occured while trying to load the file! Please ensure that it's SGA archive still exists! Info: {0}", e.Message); if (uniFile != null) uniFile.Close(); LoggingManager.HandleException(e); } // set a pseudo path that will be used when saving the file if (uniFile != null) uniFile.FilePath = GetPath(); } return uniFile; }
/// <summary> /// Tries to load the specified UniFile and returns the proper FileTool. /// </summary> /// <param name="file"></param> /// <param name="forceText">Set this to true to always use the Text-editor.</param> /// <returns></returns> static public FileTool LoadFile(UniFile file, bool forceText = false) { if (!AllowOpeningFilesTwice && s_openTools.ContainsKey(file.FilePath)) { return(s_openTools[file.FilePath]); } FileTool tmp; byte[] stream = file.ConsumeStream(); UniFile filecopy = new UniFile(stream); filecopy.FilePath = file.FilePath; if (forceText) { try { tmp = new TextEditor(filecopy); } catch (Exception e) { UIHelper.ShowError("Can't open the selected file " + file.FileName + " as Text: " + e.Message); return(null); } } else if (FileTypeManager.FileTypes.ContainsKey(filecopy.FileExtension)) { tmp = FileTypeManager.LaunchFromExt(filecopy.FileName, filecopy); } else { try { tmp = new RelicChunkyViewer(filecopy); } catch { try { filecopy = new UniFile(stream); file.Stream.Position = 0; tmp = new TextEditor(filecopy); } catch (Exception ex) { LoggingManager.SendError("Failed to open file"); LoggingManager.HandleException(ex); file.Close(); UIHelper.ShowError("Can't open the selected file " + file.FileName + ", no suitable plugin found!"); return(null); } } } tmp.OnSaved += FileTool_OnSaved; if (!s_openTools.ContainsKey(file.FilePath)) { s_openTools.Add(file.FilePath, tmp); } if (FileLoaded != null) { FileLoaded(file, tmp); } return(tmp); }
/// <exception cref="CopeDoW2Exception">Failed to load file as RBF! Visit the options and ensure that the settings correspond to the game version you're trying to modify.</exception> protected void LoadFile(UniFile file) { if (file.FileExtension == "rbf") { m_rbf = new RelicBinaryFile(file) { KeyProvider = ModManager.RBFKeyProvider, UseKeyProvider = RBFSettings.UseKeyProviderForLoading }; try { m_rbf.ReadData(); } catch (Exception ex) { throw new CopeDoW2Exception(ex, "Failed to load file as RBF! Visit the plugin's options " + "and ensure that the settings correspond to " + "the game version you're trying to modify."); } } else if (file.FileExtension == "attr_pc") { try { var attribStruct = BAFReader.Read(file.Stream); file.Close(); m_rbf = new RelicBinaryFile(attribStruct) {FilePath = file.FilePath, UseKeyProvider = false}; } catch (Exception ex) { throw new CopeDoW2Exception(ex, "Failed to load file as attr_pc!"); } } file.Close(); m_rbfEditorCore.Analyze(m_rbf.AttributeStructure.Root); }
private static void DragDropGeneral(DragEventArgs e) { if (e.Effect == DragDropEffects.Move) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var fileNames = (string[]) e.Data.GetData(DataFormats.FileDrop); foreach (string s in fileNames) { // only one SGA / module at a time (currently)! if (s.EndsWith(".sga")) { if (ModManager.IsAnythingLoaded && UIHelper.ShowYNQuestion("Warning!", "Opening a SGA archive will close all other archives and tabs!") == DialogResult.No) return; ModManager.LoadSGAFile(s); return; } if (s.EndsWith(".module")) { if (ModManager.IsAnythingLoaded && UIHelper.ShowYNQuestion("Warning!", "Opening another module will close the current mod with all it's tabs and SGAs! Continue anyway?") == DialogResult.No) return; ModManager.LoadModule(s); return; } var tmp = new UniFile(s); try { FileManager.LoadFile(tmp); } catch (Exception ex) { tmp.Close(); UIHelper.ShowError(ex.Message); return; } } } } }
/// <summary> /// Tries to load the specified UniFile and returns the proper FileTool. /// </summary> /// <param name="file"></param> /// <param name="forceText">Set this to true to always use the Text-editor.</param> /// <returns></returns> static public FileTool LoadFile(UniFile file, bool forceText = false) { if (!AllowOpeningFilesTwice && s_openTools.ContainsKey(file.FilePath)) return s_openTools[file.FilePath]; FileTool tmp; byte[] stream = file.ConsumeStream(); UniFile filecopy = new UniFile(stream); filecopy.FilePath = file.FilePath; if (forceText) { try { tmp = new TextEditor(filecopy); } catch (Exception e) { UIHelper.ShowError("Can't open the selected file " + file.FileName +" as Text: " + e.Message); return null; } } else if (FileTypeManager.FileTypes.ContainsKey(filecopy.FileExtension)) tmp = FileTypeManager.LaunchFromExt(filecopy.FileName, filecopy); else { try { tmp = new RelicChunkyViewer(filecopy); } catch { try { filecopy = new UniFile(stream); file.Stream.Position = 0; tmp = new TextEditor(filecopy); } catch(Exception ex) { LoggingManager.SendError("Failed to open file"); LoggingManager.HandleException(ex); file.Close(); UIHelper.ShowError("Can't open the selected file " + file.FileName + ", no suitable plugin found!"); return null; } } } tmp.OnSaved += FileTool_OnSaved; if (!s_openTools.ContainsKey(file.FilePath)) s_openTools.Add(file.FilePath, tmp); if (FileLoaded != null) FileLoaded(file, tmp); return tmp; }