Exemple #1
0
        public static void OneOffMain(String[] args)
        {
            DirectoryInfo root = new DirectoryInfo(@"D:\Users\David\My Documents\Visual Studio Projects\Anolis\_resources\xpize");

            String expr = @"comp:164,628;MCE\GenLong.png,0,0,164,817;Generator\Windows\system32\newdev.dll\101.png,19,144;MCE\GenStripe.png,160,0";

            CompositedImage ci = new CompositedImage(expr, root);

            ci.Save(@"D:\Users\David\Desktop\hdwiz\Test.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
        }
Exemple #2
0
        private void __compImages_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (__compImages.SelectedIndex == -1)
            {
                LoadImage(null);
            }
            else
            {
                CompositedImage image = (CompositedImage)__compImages.Items[__compImages.SelectedIndex];

                LoadImage(image);
            }
        }
Exemple #3
0
        private String ProcessCompositedImage(String compExpr)
        {
            Boolean isUpdated = false;

            CompositedImage img = new CompositedImage(compExpr, _root);

            foreach (CompositedLayer layer in img.Layers)
            {
                String nonDupeFn = _reverse.FileIsDuplicate(layer.ImageRelativeFileName);
                if (nonDupeFn != null)
                {
                    layer.ImageRelativeFileName = nonDupeFn;
                    isUpdated = true;
                }
            }

            return(isUpdated ? img.ToString() : null);
        }
Exemple #4
0
        private void LoadImage(CompositedImage image)
        {
            __compLayers.Items.Clear();

            _currentImage = image;

            if (image == null)
            {
                LoadLayer(null);
            }
            else
            {
                __compLayers.Items.Add("Final Image");

                foreach (CompositedLayer layer in image.Layers)
                {
                    __compLayers.Items.Add(layer);
                }

                __compLayers.SelectedIndex = 0;
            }
        }
Exemple #5
0
        protected override Boolean PatchFile(String fileName)
        {
            List <PatchResource> patchResources = new List <PatchResource>();

            foreach (PatchResourceSet set in _resourceSets)
            {
                if (EvaluatePatchResourceSet(set, fileName))
                {
                    // HACK: This just adds them together into a massive list. If the same name is mentioned it'll be overwritten several times
                    // fortunately it isnt' very expensive as only the last "final" one counts, but could do with filtering at this stage maybe?

                    patchResources.AddRange(set.Resources);
                }
                else
                {
                    Package.Log.Add(LogSeverity.Info, "Expression evaluation non-one: " + set.Condition.ExpressionString + ", did not process " + set.Resources.Count + " resources");
                }
            }

            if (patchResources.Count == 0)
            {
                Package.Log.Add(LogSeverity.Warning, "No resources to patch: " + fileName);
                return(false);
            }

            try {
                // for now, use lazy-load under all circumstances. In future analyse the Resources list to see if it's necessary or not
                // but the performance impact is minimal and it's the safest option, so keep it as it is
                using (ResourceSource source = ResourceSource.Open(fileName, false, ResourceSourceLoadMode.LazyLoadData)) {
                    List <String> tempFiles = new List <String>();

                    foreach (PatchResource res in patchResources)
                    {
                        if (res.Source.StartsWith("comp:", StringComparison.OrdinalIgnoreCase))
                        {
                            CompositedImage comp = new CompositedImage(res.Source, Package.RootDirectory);

                            DirectoryInfo packageTempDirectory = new DirectoryInfo(P.Combine(Package.RootDirectory.FullName, "Temp"));
                            if (!packageTempDirectory.Exists)
                            {
                                packageTempDirectory.Create();
                            }

                            // I think not using the *.bmp extension messes up Bitmap import
                            String tempFileName = PackageUtility.GetUnusedFileName(P.Combine(packageTempDirectory.FullName, P.GetFileName(Path) + res.Name) + ".bmp");

                            comp.Save(tempFileName, System.Drawing.Imaging.ImageFormat.Bmp);

                            res.File = tempFileName;
                            tempFiles.Add(tempFileName);
                        }
                        else
                        {
                            res.File = res.Source;
                        }

                        if (!File.Exists(res.File))
                        {
                            Package.Log.Add(LogSeverity.Error, "Data File not found: " + res.File);
                            continue;
                        }

                        ResourceTypeIdentifier typeId = ResourceTypeIdentifier.CreateFromString(res.Type, true);
                        ResourceIdentifier     nameId = ResourceIdentifier.CreateFromString(res.Name);
                        UInt16 langId = String.IsNullOrEmpty(res.Lang) ? UInt16.MaxValue : UInt16.Parse(res.Lang, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture);


                        if (langId == UInt16.MaxValue)                                // if the lang="" attribute was not specified

                        {
                            ResourceName name = source.GetName(typeId, nameId);

                            if (name == null)                              // if the specified name does not exist

                            {
                                if (res.Add)
                                {
                                    UInt16 sysLang = (UInt16)CultureInfo.InvariantCulture.LCID;

                                    ResourceData data = ResourceData.FromFileToAdd(res.File, sysLang, source);
                                    source.Add(typeId, nameId, sysLang, data);
                                }
                                else
                                {
                                    // Error

                                    String sourcePath = source.Name;

                                    Anolis.Core.Source.FileResourceSource frs = source as Anolis.Core.Source.FileResourceSource;
                                    if (frs != null)
                                    {
                                        sourcePath = frs.FileInfo.FullName;
                                    }

                                    Package.Log.Add(LogSeverity.Warning, "Resource name not found: " + sourcePath + '\\' + typeId.ToString() + '\\' + nameId.FriendlyName);
                                }
                            }
                            else
                            {
                                foreach (ResourceLang lang in name.Langs)
                                {
                                    ResourceData data = ResourceData.FromFileToUpdate(res.File, lang);
                                    lang.SwapData(data);
                                }
                            }
                        }
                        else                             // if the lang="" attribute was specified

                        {
                            ResourceLang lang = source.GetLang(typeId, nameId, langId);
                            if (lang == null)
                            {
                                ResourceData data = ResourceData.FromFileToAdd(res.File, langId, source);
                                source.Add(typeId, nameId, langId, data);
                            }
                            else
                            {
                                ResourceData data = ResourceData.FromFileToUpdate(res.File, lang);
                                lang.SwapData(data);
                            }
                        }
                    }                    //foreach

                    // note that Win32ResourceSource now recomptues the PE checksum by itself
                    source.CommitChanges();

                    foreach (String tempFile in tempFiles)
                    {
                        File.Delete(tempFile);
                    }

                    return(true);
                }                //using source
            } catch (AnolisException aex) {
                Package.Log.Add(LogSeverity.Error, "Patch Exception: " + aex.Message);

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                throw;
            }
        }
Exemple #6
0
 private void LoadFinalImage(CompositedImage image)
 {
     __compPreview.Image = image.ToBitmap();
 }
Exemple #7
0
        private void ProcessElement(DirectoryInfo root, XmlElement element, List <String> files)
        {
            // ideally HashSet<String> should be used, but it's a 3.5 class

            foreach (String attributeName in FileAttributes)
            {
                if (attributeName == "path" && element.Name == "file")
                {
                    continue;
                }

                String attributeValue = element.GetAttribute(attributeName);
                if (attributeValue.Length == 0)
                {
                    continue;
                }

                attributeValue = attributeValue.ToLowerInvariant();

                if (attributeValue.StartsWith("comp:", StringComparison.OrdinalIgnoreCase))
                {
                    // get the paths of the images

                    try {
                        CompositedImage img = new CompositedImage(attributeValue, root);
                        foreach (CompositedLayer layer in img.Layers)
                        {
                            String fn = layer.ImageFileName.Substring(root.FullName.Length + 1).ToLowerInvariant();

                            if (!files.Contains(fn))
                            {
                                files.Add(fn);
                            }
                        }
                        _compImages.Add(img);
                    } catch (FileNotFoundException fex) {
                        files.Add(fex.FileName);
                    }
                }
                else
                {
                    if (!files.Contains(attributeValue) && !attributeValue.Contains("%"))
                    {
                        files.Add(attributeValue);
                    }
                }
            }

            List <XmlNode> commentsToRemove = new List <XmlNode>();

            foreach (XmlNode child in element.ChildNodes)
            {
                if (child is XmlComment)
                {
                    commentsToRemove.Add(child);
                }
                else
                {
                    XmlElement childElement = child as XmlElement;
                    if (childElement != null)
                    {
                        ProcessElement(root, childElement, files);
                    }
                }
            }

            foreach (XmlNode comment in commentsToRemove)
            {
                element.RemoveChild(comment);
            }
        }