private static void UnregisterFileType(string name, string extension)
 {
     try
     {
         Registry.ClassesRoot.DeleteSubKeyTree(name);
         Registry.ClassesRoot.DeleteSubKeyTree(extension);
     }
     catch (Exception ex)
     {
         MessageEngine.AddError(ex);
     }
 }
        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));
        }
        private void FileProcessWorker(object state)
        {
            var files = state as object[];

            if (files == null)
            {
                Compleated();
                return;
            }
            int  consecutiveErrors       = 0;
            bool lastItterationHadErrors = false;

            MessageEngine.AddInformation(this, "...Start processing files...");
            foreach (object file in files)
            {
                if (_cancel)
                {
                    break;
                }
                try
                {
                    foreach (IFileHandler fileHandler in _fileHandlers)
                    {
                        if (fileHandler.CanProcess(file))
                        {
                            fileHandler.ProcessFile(file, IsCanceled);
                        }
                    }
                    var compositFile = file as CompositFile;
                    if (compositFile != null)
                    {
                        compositFile.HandleContentUpdatedExternaly();
                    }
                    lastItterationHadErrors = false;
                }
                catch (Exception ex)
                {
                    MessageEngine.AddError(ex);
                    consecutiveErrors = lastItterationHadErrors ? consecutiveErrors + 1 : 1;
                    if (consecutiveErrors == ConsecutiveErrorsThreshold)
                    {
                        _cancel = true;
                        break;
                    }
                    lastItterationHadErrors = true;
                }
            }
            MessageEngine.AddInformation(this, string.Format("...Processing files {0}...", _cancel ? "canceled" : "ended"));
            Compleated();
        }
Пример #4
0
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as CompositFile;

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

            foreach (ModPlugIn modPlugIn in CrcsSettings.Current.GetModPlugIns(file.Name))
            {
                if (modPlugIn.ModifyClasses && !file.IsDeCompiled)
                {
                    continue;
                }
                var arguments = new StringBuilder();
                arguments.Append("\"").Append(file.ClassesFolder).Append("\"");
                var apkFile = file as ApkFile;
                if (apkFile != null)
                {
                    if (modPlugIn.ModifyResource && !apkFile.IsDeCoded)
                    {
                        continue;
                    }
                    arguments.Append(" \"").Append(apkFile.ResourceFolder).Append("\"");
                }


                var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));
                if (
                    ep.Execute(modPlugIn.ProgramFile, arguments.ToString(), Path.GetDirectoryName(modPlugIn.ProgramFile)) !=
                    0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(modPlugIn.ProgramFile)));
                }
            }
        }
        public static void InstallFrameworkIfMissing(ApkFile apkFile)
        {
            IEnumerable <string> frameworkFiles = apkFile.Project.Properties.FrameWorkFiles;

            if (frameworkFiles.Count() == 0)
            {
                return;
            }
            string apkToolFrameWorkTag = apkFile.Project.Properties.ApkToolFrameWorkTag;

            apkToolFrameWorkTag = string.IsNullOrWhiteSpace(apkToolFrameWorkTag)
                                      ? apkFile.Project.Name
                                      : apkToolFrameWorkTag;
            string[] installedFrameworkFiles = Directory.GetFiles(CrcsSettings.Current.ApkToolFrameWorkFolder,
                                                                  "*" + apkToolFrameWorkTag + "*.apk",
                                                                  SearchOption.TopDirectoryOnly);
            if (frameworkFiles.Count() == installedFrameworkFiles.Length)
            {
                return;
            }

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

            foreach (string file in frameworkFiles)
            {
                var    arguments   = new StringBuilder();
                string apkToolFile = apkFile.Project.Solution.Properties.ApkToolFile;
                arguments.Append("-jar \"").Append(apkToolFile).Append("\"");
                arguments.Append(" if \"").Append(file).Append("\"");
                if (!string.IsNullOrWhiteSpace(apkToolFrameWorkTag))
                {
                    arguments.Append(" ").Append(apkToolFrameWorkTag);
                }

                if (
                    ep.Execute(CrcsSettings.Current.JavaFile, arguments.ToString(), Path.GetDirectoryName(apkToolFile)) != 0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(apkToolFile)));
                }
            }
        }
        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 (!file.Project.Properties.ReSignApkFiles)
            {
                return;
            }

            MessageEngine.AddInformation(this, string.Format("Createing a new signature for {0}", file.Name));

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

            var arguments = new StringBuilder();

            arguments.Append("-jar \"").Append(_signApkFile).Append("\"");
            arguments.Append(" \"").Append(_certificateFile).Append("\"");
            arguments.Append(" \"").Append(_certificateKeyFile).Append("\"");
            arguments.Append(" \"").Append(file.FileSystemPath).Append("\"");
            arguments.Append(" \"").Append(file.FileSystemPath + ".tmpsign").Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(file.FileSystemPath)) == 0)
            {
                FileUtility.MoveFile(file.FileSystemPath + ".tmpsign", file.FileSystemPath);
            }
            else
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_signApkFile)));
            }
        }
Пример #7
0
 public void Open(string fileSystemPath)
 {
     if (fileSystemPath == null)
     {
         return;
     }
     if (!File.Exists(fileSystemPath))
     {
         return;
     }
     if (new FileInfo(fileSystemPath).Length == 0)
     {
         return;
     }
     using (
         FileStream stream = File.Open(fileSystemPath, FileMode.Open, FileAccess.Read,
                                       FileShare.Delete | FileShare.ReadWrite))
     {
         _encoding = stream.DetectEncoding();
         using (var reader = new StreamReader(stream, _encoding))
         {
             _textEditor.Text = reader.ReadToEnd();
         }
     }
     _originalFileCheckSum = null;
     EvaluateDirty();
     try
     {
         _textEditor.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(fileSystemPath);;
     }
     catch (HighlightingDefinitionInvalidException ex)
     {
         MessageEngine.AddError(ex);
     }
     _textEditor.ShowMatchingBracket = true;
     //_textEditor.Document.FoldingManager.UpdateFoldings(null, null);
     //            _textEditor.Document.FoldingManager.FoldingStrategy =
 }
        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));
            }

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

            string arguments = string.Format("-c 4 \"{0}\"", file.FileSystemPath);

            if (ep.Execute(_zipAlignFile, arguments, Path.GetDirectoryName(_zipAlignFile)) == 0)
            {
                return;
            }

            MessageEngine.AddInformation(this, string.Format("Zipaligning {0}", file.Name));

            arguments = string.Format("-f 4 \"{0}\" \"{1}.tmpzipalign\"", file.FileSystemPath, file.FileSystemPath);

            if (ep.Execute(_zipAlignFile, arguments, Path.GetDirectoryName(_zipAlignFile)) == 0)
            {
                FileUtility.MoveFile(file.FileSystemPath + ".tmpzipalign", file.FileSystemPath);
            }
            else
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_zipAlignFile)));
            }
        }