public static void installFonts(SmashOverlayGenerator form, string fontName, PrivateFontCollection pfc) { // Try install the font string fontPath = ListBoxFcns.getResourcePath(form.ProductName, "font", fontName); Stream fontStream = form.myAssembly.GetManifestResourceStream(fontPath); //create an unsafe memory block for the data System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length); //create a buffer to read in to Byte[] fontData = new Byte[fontStream.Length]; //fetch the font program from the resource fontStream.Read(fontData, 0, (int)fontStream.Length); //copy the bytes to the unsafe memory block Marshal.Copy(fontData, 0, data, (int)fontStream.Length); // We HAVE to do this to register the font to the system (Weird .NET bug !) uint cFonts = 0; AddFontMemResourceEx(data, (uint)fontData.Length, IntPtr.Zero, ref cFonts); //pass the font to the font collection pfc.AddMemoryFont(data, (int)fontStream.Length); //close the resource stream fontStream.Close(); //free the unsafe memory Marshal.FreeCoTaskMem(data); }
public static string CreateDatabase(string productName) { string retStr = ""; dataDir = @"C:\OverlayGenerator\Data"; dbPath = @"C:\OverlayGenerator\Data\Generator.sqlite"; if (!Directory.Exists(dataDir)) { Directory.CreateDirectory(dataDir); } if (!File.Exists(dbPath)) { string dbFile = ListBoxFcns.getResourcePath(productName, "database", "Generator.sqlite"); if (dbFile != null) { Stream dbStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(dbFile); FileStream outStream = new FileStream(@"C:\OverlayGenerator\Data\Generator.sqlite", FileMode.Create); for (int i = 0; i < dbStream.Length; i++) { outStream.WriteByte((byte)dbStream.ReadByte()); } } else { SQLiteConnection.CreateFile(dbPath); if (conn == null) { GetConnection(); } bool create = CreateTables(); if (create) { retStr += "DB Successfully Created\r\n"; } else { retStr += "DB Creation Failed\r\n"; } bool initialInsert = InitialFillData(); if (initialInsert) { retStr += "DB Successfully Filled\r\n"; } else { retStr += "DB Failed Initial Data Fill\r\n"; } } } if (conn == null) { GetConnection(); } return(retStr); }
public static void CopyDBToProjDir(string productName, string filePath) { FileStream outStream = null; FileStream dbStream = null; if (filePath == null) { if (debug) { filePath = @"C:\Users\BrandonADMIN\Documents\FightingGameOverlayGenerator\SmashOverlayGeneratorMk2\Generator.sqlite"; } else { return; } } else { return; } try{ string dbFile = ListBoxFcns.getResourcePath(productName, "database", "Generator.sqlite"); if (dbFile != null) { outStream = new FileStream(@filePath, FileMode.Open); dbStream = new FileStream(@"C:\OverlayGenerator\Data\Generator.sqlite", FileMode.Open); for (int i = 0; i < dbStream.Length; i++) { outStream.WriteByte((byte)dbStream.ReadByte()); } } }catch { if (outStream != null) { outStream.Close(); } if (dbStream != null) { dbStream.Close(); } deleteDB(); } }