public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as ApkFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }

            if (!FolderUtility.Empty(file.ResourceFolder))
            {
                return;
            }

            MessageEngine.AddInformation(this, string.Format("Extracting content png files from {0}", file.Name));
            using (var zf = new ZipFile(file.FileSystemPath))
            {
                zf.Extract(
                    zf.Entries.Where(
                        x =>
                        x.Name.EndsWith(".PNG", StringComparison.OrdinalIgnoreCase) &&
                        !x.Name.EndsWith(".9.PNG", StringComparison.OrdinalIgnoreCase)), file.ResourceFolder, true);
            }
        }
Beispiel #2
0
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as ApkFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }

            if (FolderUtility.Empty(file.ResourceFolder))
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Updating {0} with optimized png files", file.Name));
            using (var zf = new AndroidArchive(file.FileSystemPath))
            {
                foreach (string pngFile in file.GetPngFilesToOptimize())
                {
                    zf.Add(pngFile, FolderUtility.GetRelativePath(file.ResourceFolder, pngFile), CompressionType.Store);
                }
            }
        }
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as ApkFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }

            if (FolderUtility.Empty(file.ResourceFolder))
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Optimizing png files for {0}", file.Name));
            int allFiles       = 0;
            int optimizedFiles = 0;

            foreach (string pngFile in file.GetPngFilesToOptimize())
            {
                if (isCanceled())
                {
                    return;
                }
                var arguments = new StringBuilder();
                arguments.Append(" -o7 -quiet");
                arguments.Append(" -out \"").Append(pngFile + ".oz").Append("\"");
                arguments.Append(" \"").Append(pngFile).Append("\"");

                var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));

                if (ep.Execute(_optiPngFile, arguments.ToString(), Path.GetDirectoryName(pngFile)) != 0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_optiPngFile)));
                }
                if (File.Exists(pngFile + ".oz"))
                {
                    FileUtility.MoveFile(pngFile + ".oz", pngFile);
                    optimizedFiles++;
                }
                allFiles++;
            }
            file.SetPngOptimized();
            MessageEngine.AddInformation(this,
                                         string.Format("\t {0} of {1} png files optimized", optimizedFiles, allFiles));
        }