public void TestAddDialogResource() { Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase); string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)); string gutilsdll = Path.Combine(uriPath, @"Binaries\gutils.dll"); int dialogsBefore = 0; using (ResourceInfo ri = new ResourceInfo()) { ri.Load(gutilsdll); dialogsBefore = ri.Resources[new ResourceId(Kernel32.ResourceTypes.RT_DIALOG)].Count; } string targetFilename = Path.Combine(Path.GetTempPath(), "testAddDialogResource.dll"); File.Copy(gutilsdll, targetFilename, true); // copy an existing dialog inside gutils.dll DialogResource sourceDialog = new DialogResource(); sourceDialog.Name = new ResourceId("GABRTDLG"); sourceDialog.LoadFrom(gutilsdll); sourceDialog.Name = new ResourceId("NEWGABRTDLG"); Console.WriteLine(targetFilename); sourceDialog.SaveTo(targetFilename); // check that the dialog was written sourceDialog.LoadFrom(targetFilename); DumpResource.Dump(sourceDialog); using (ResourceInfo ri = new ResourceInfo()) { ri.Load(targetFilename); int dialogsAfter = ri.Resources[new ResourceId(Kernel32.ResourceTypes.RT_DIALOG)].Count; DumpResource.Dump(ri); Assert.AreEqual(dialogsBefore + 1, dialogsAfter); } }
public void TestLoadDialogResource() { foreach (TestLoadDialogResourceTestDataEntry test in testdata) { Console.WriteLine("Loading {0}: {1}", test.Filename, test.ResourceId); DialogResource rc = new DialogResource(); rc.Name = test.ResourceId; rc.LoadFrom(test.Filename); Console.WriteLine("DialogResource: {0}, {1}", rc.Name, rc.TypeName); Console.WriteLine(rc); Assert.AreEqual(test.NumberOfDialogControls, rc.Template.ControlCount); Assert.AreEqual(test.NumberOfDialogControls, rc.Template.Controls.Count); } }
public void TestLoadDialogResources() { Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase); string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)); string filename = Path.Combine(uriPath, @"Binaries\gutils.dll"); using (ResourceInfo ri = new ResourceInfo()) { Console.WriteLine("Loading: {0}", filename); ri.Load(filename); foreach (DialogResource rc in ri[Kernel32.ResourceTypes.RT_DIALOG]) { Console.WriteLine("DialogResource: {0}, {1}", rc.Name, rc.TypeName); Console.WriteLine(rc); } // two dialogs Assert.AreEqual(2, ri[Kernel32.ResourceTypes.RT_DIALOG].Count); DialogResource dlg = (DialogResource)ri[Kernel32.ResourceTypes.RT_DIALOG][0]; Assert.AreEqual("GABRTDLG", dlg.Name.Name); // the first one is called "Printing" DialogTemplate printingTemplate = (DialogTemplate)dlg.Template; Assert.AreEqual(38, printingTemplate.x); Assert.AreEqual(18, printingTemplate.y); Assert.AreEqual(128, printingTemplate.cx); Assert.AreEqual(83, printingTemplate.cy); Assert.AreEqual(3, printingTemplate.ControlCount); Assert.AreEqual(3, printingTemplate.Controls.Count); Assert.AreEqual("Printing", printingTemplate.Caption); Assert.AreEqual("MS Shell Dlg", printingTemplate.TypeFace); Assert.AreEqual(8, printingTemplate.PointSize); // the first control is called "Printing Table" DialogTemplateControl printingTable = (DialogTemplateControl)printingTemplate.Controls[0]; Assert.AreEqual("Printing Table", printingTable.CaptionId.Name); Assert.AreEqual(23, printingTable.x); Assert.AreEqual(18, printingTable.y); Assert.AreEqual(87, printingTable.cx); Assert.AreEqual(8, printingTable.cy); Assert.AreEqual(101, printingTable.Id); } }
private string Handler_Replace_Dialog(Match theM) { DialogResource aDlg = new DialogResource(); aDlg.ID = theM.Groups[1].Value; aDlg.Text = string.Empty; //TODO aDlg.Width = int.Parse(theM.Groups[3].Value); aDlg.Height = int.Parse(theM.Groups[4].Value); if (!myResourceDict.ContainsKey(aDlg.ID)) { myResourceDict.Add(aDlg.ID, aDlg); } StringBuilder aSB = new StringBuilder(); aSB.Append(aDlg.ID); aSB.Append(theM.Groups[2]); aSB.Append(' '); aSB.Append(aDlg.Width); aSB.Append(','); aSB.Append(' '); aSB.Append(aDlg.Height); if (myExclDialogIDs.BinarySearch(aDlg.ID) >= 0) { aSB.Append(theM.Groups[5].Value); } else { string aTemp = ourRX_Control.Replace(theM.Groups[5].Value, myEv_Control); aTemp = ourRX_EditControl.Replace(aTemp, myEv_EditControl); aSB.Append(aTemp); } return(aSB.ToString()); }
public static void Dump(DialogResource rc) { Console.WriteLine(rc.ToString()); }
private static void ScrapeDialog(StringBuilder language, StringBuilder normal, DialogResource dialogRes) { int previousLanguageLength = language.Length; string headerComment = Comment; switch (dialogRes.Template) { case DialogTemplate dialog: ScrapeDialogTemplate(language, normal, dialog); headerComment += "DIALOG"; break; case DialogExTemplate dialogEx: ScrapeDialogTemplate(language, normal, dialogEx); headerComment += "DIALOGEX"; break; } headerComment += $" : {dialogRes.Name}{Environment.NewLine}{Environment.NewLine}"; if (normal.Length != 0) { normal.Insert(0, headerComment); } if (language.Length != previousLanguageLength) { language.Insert(previousLanguageLength, headerComment); language.Insert(previousLanguageLength, Environment.NewLine); } }
private void updateResource() { string filenameDownloader = WorkingDir + DownloaderFileName; string filenameDownloaderSatelliteResource = WorkingDir + constDownloaderSatelliteResource; // Look up the satellite resource ResourceInfo rcInfo = new ResourceInfo(); rcInfo.Load(filenameDownloader); rcInfo.Unload(); // Release the module so its can be saved // Chinese Satellite Resource msResIdToFind = 1000; if (AppResource.Culture.Name == "en-US") { // English Satellite Resource msResIdToFind = 1002; } GenericResource satelliteRC = (GenericResource)rcInfo.Resources[new ResourceId(1001)].Find(FindRes); byte[] temp = satelliteRC.WriteAndGetBytes(); MemoryStream memSatellite = new MemoryStream(1024 * 10); memSatellite.Write(temp, 0, temp.Length); memSatellite.Position = 0; //Create the decompressed file. using (FileStream fileSatellite = File.Create(filenameDownloaderSatelliteResource)) { using (GZipStream Decompress = new GZipStream(memSatellite, CompressionMode.Decompress)) { readWriteStream(Decompress, fileSatellite); } } // Load the satellite resource rcInfo = new ResourceInfo(); rcInfo.Load(filenameDownloaderSatelliteResource); rcInfo.Unload(); // Release the module so its can be saved // Begin the batch update to the designated module to speed up the process ResourceInfo.BeginBatchUpdate(filenameDownloaderSatelliteResource); try { // ========================== // Modify the Banner // ========================== // Look up the bitmap resource if (BannerBitmapFullPath.Trim() != "") { msResIdToFind = 207; BitmapResource bmpRC = (BitmapResource)rcInfo[Kernel32.ResourceTypes.RT_BITMAP].Find(FindRes); if (bmpRC == null) { throw new ApplicationException( AppResource.ResBitmap207NotFound); } BitmapFile bmpFile = new BitmapFile(BannerBitmapFullPath.Trim()); bmpRC.Bitmap = bmpFile.Bitmap; bmpRC.SaveTo(filenameDownloaderSatelliteResource); } // ========================== // Modify the Icon // ========================== // Look up the ICON resource if (IconFullPath.Trim() != "") { msResIdToFind = 128; IconDirectoryResource icoRC = (IconDirectoryResource)rcInfo[Kernel32.ResourceTypes.RT_GROUP_ICON].Find(FindRes); if (icoRC == null) { throw new ApplicationException(AppResource.ResIcon128NotFound); } IconFile icoFile = new IconFile(IconFullPath.Trim()); uint j = 1; icoRC.Icons.RemoveRange(0, icoRC.Icons.Count); icoRC.SaveTo(filenameDownloaderSatelliteResource); foreach (IconFileIcon icoFileIcon in icoFile.Icons) { IconResource icoRes = new IconResource(icoFileIcon, new ResourceId(j), 1033); icoRes.Name = new ResourceId(j++); icoRC.Icons.Add(icoRes); } icoRC.SaveTo(filenameDownloaderSatelliteResource); } // ========================== // Modify the main dialog box // ========================== // Look up the dialog resource msResIdToFind = 201; DialogResource dlgRC = (DialogResource)rcInfo[Kernel32.ResourceTypes.RT_DIALOG].Find(FindRes); if (dlgRC == null) { throw new ApplicationException(AppResource.ResDialog201NotFound); } // Find the designated label control msCtrlIdToFind = 1010; DialogTemplateControlBase ctrl = dlgRC.Template.Controls.Find(FindDlgControl); ctrl.CaptionId.Name = string.Format(ctrl.CaptionId.Name, DownloaderDisplayName); // Find the designated link control msCtrlIdToFind = 1006; ctrl = dlgRC.Template.Controls.Find(FindDlgControl); ctrl.CaptionId.Name = string.Format(ctrl.CaptionId.Name, DownloaderHomeUrl); dlgRC.SaveTo(filenameDownloaderSatelliteResource); // =================================================== // Embed the specified .Torrent file into the resource // =================================================== // Look up the torrent resource msResIdToFind = 1021; GenericResource torrentRC = (GenericResource)rcInfo.Resources[new ResourceId(1022)].Find(FindRes); if (torrentRC == null) { throw new ApplicationException(AppResource.ResTorrentSlot2011NotFound); } FileStream fs = new FileStream(MetafileFullPath, FileMode.Open); temp = new byte[fs.Length]; fs.Read(temp, 0, temp.Length); fs.Close(); torrentRC.Data = temp; torrentRC.SaveTo(filenameDownloaderSatelliteResource); // =================================================== // Embed the specified disclaimer file into the resource // =================================================== // Look up the disclaimer resource if (DisclaimerFullPath.Trim() != "") { msResIdToFind = 40111; GenericResource disclaimerRC = (GenericResource)rcInfo.Resources[new ResourceId(40112)].Find(FindRes); if (disclaimerRC == null) { throw new ApplicationException(AppResource.ResDisclaimerSlot40112NotFound); } fs = new FileStream(DisclaimerFullPath.Trim(), FileMode.Open); temp = new byte[fs.Length]; fs.Read(temp, 0, temp.Length); fs.Close(); disclaimerRC.Data = temp; disclaimerRC.SaveTo(filenameDownloaderSatelliteResource); } // ================================== // Modify the strings in the resource // ================================== // Display Name StringResource stringRC = null; int[] stringID = new int[] { 1112, 13015, 13016, 13017, 13018, 13019, 13027 }; for (int i = 0; i < stringID.Length; i++) { int sID = stringID[i]; // Check if the string resource has been loaded in the last string block or not. if (stringRC == null || !stringRC.Strings.ContainsKey((ushort)sID)) { msResIdToFind = StringResource.GetBlockId(sID); stringRC = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes); if (stringRC == null) { throw new ApplicationException( string.Format(AppResource.ResStringTemplateNotFound, sID)); } } stringRC.Strings[(ushort)sID] = string.Format(stringRC.Strings[(ushort)sID], DownloaderDisplayName); // Leave the modified string resource unsaved until all the strings in the string block are done. if (stringID.Length == (i + 1) || !stringRC.Strings.ContainsKey((ushort)stringID[i + 1])) { stringRC.SaveTo(filenameDownloaderSatelliteResource); } } // Google Analytics Profile ID msResIdToFind = StringResource.GetBlockId(1113); stringRC = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes); if (stringRC == null) { throw new ApplicationException( string.Format(AppResource.ResStringTemplateNotFound, 1113)); } stringRC.Strings[1113] = string.Format(stringRC.Strings[1113], GoogleAnalyticsProfileID); stringRC.SaveTo(filenameDownloaderSatelliteResource); // Downloader GUID msResIdToFind = StringResource.GetBlockId(40401); stringRC = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes); if (stringRC == null) { throw new ApplicationException( string.Format(AppResource.ResStringTemplateNotFound, 40401)); } stringRC.Strings[40401] = string.Format(stringRC.Strings[40401], DownloaderGuid); stringRC.SaveTo(filenameDownloaderSatelliteResource); // Online FAQ URL if (OnlineFaqUrl.Trim() != "") { msResIdToFind = StringResource.GetBlockId(13020); stringRC = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes); if (stringRC == null) { throw new ApplicationException( string.Format(AppResource.ResStringTemplateNotFound, 13020)); } stringRC.Strings[13020] = OnlineFaqUrl; stringRC.SaveTo(filenameDownloaderSatelliteResource); } // Event ID if (PromotionEventID.Trim() != "") { msResIdToFind = StringResource.GetBlockId(1104); stringRC = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes); if (stringRC == null) { throw new ApplicationException( string.Format(AppResource.ResStringTemplateNotFound, 1104)); } stringRC.Strings[1104] = string.Format(stringRC.Strings[1104], PromotionEventID); stringRC.SaveTo(filenameDownloaderSatelliteResource); } // Event Server URL if (PromotionEventID.Trim() != "") { msResIdToFind = StringResource.GetBlockId(1101); stringRC = (StringResource)rcInfo[Kernel32.ResourceTypes.RT_STRING].Find(FindRes); if (stringRC == null) { throw new ApplicationException( string.Format(AppResource.ResStringTemplateNotFound, 1101)); } // Conver the URL to base64 encoded string stringRC.Strings[1101] = Convert.ToBase64String(Encoding.ASCII.GetBytes(PromotionEventServerUrl)); stringRC.SaveTo(filenameDownloaderSatelliteResource); } } catch (Exception oEx) { throw oEx; } finally { // Commit the batch updates to the module ResourceInfo.EndBatchUpdate(); } }