コード例 #1
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("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);
            }
        }
コード例 #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);
                }
            }
        }
コード例 #3
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 (!file.IsDeCoded)
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Encoding resources for {0}", file.Name));

            DecodeHandler.InstallFrameworkIfMissing(file);

            FileUtility.DeleteFile(file.UnsignedFile);
            var ep        = new ExecuteProgram((message) => MessageEngine.AddInformation(this, message));
            var arguments = new StringBuilder();

            arguments.Append("-jar \"").Append(_apkToolFile).Append("\"");
            if (_verbose)
            {
                arguments.Append(" -v");
            }
            arguments.Append(" b -f \"").Append(file.ResourceFolder).Append("\"");
            arguments.Append(" \"").Append(file.UnsignedFile).Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(_apkToolFile)) != 0)
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_apkToolFile)));
            }
            //ZipFile.ExtractAll(file.UnsignedFile, file.UnsignedFolder, true);
            using (var zf = new AndroidArchive(file.FileSystemPath, CrcsSettings.Current.OnlyStoreFileTypes))
            {
                zf.MergeZipFile(file.UnsignedFile, true);
                //foreach (string resFile in Directory.GetFiles(file.UnsignedFolder, "*.*", SearchOption.AllDirectories))
                //{
                //    if (resFile.IndexOf(@"\META-INF\", StringComparison.Ordinal) >= 0) continue;
                //    if (resFile.EndsWith("AndroidManifest.xml", StringComparison.OrdinalIgnoreCase)) continue;
                //    zf.Add(resFile, FolderUtility.GetRelativePath(file.UnsignedFolder, resFile));
                //}
            }
        }
コード例 #4
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("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));
        }
コード例 #5
0
        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();
        }
コード例 #6
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));
            }

            if (!file.CanDecompile)
            {
                return;
            }
            if (file.IsDeCompiled)
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Decompiling classes for {0}", file.Name));
            Directory.CreateDirectory(file.ClassesFolder);
            string dexFile = null;
            string classesFile;

            if (file.ContainsClassesDex)
            {
                dexFile = FileUtility.ExtractToTempDir(file.FileSystemPath, "classes.dex");
                if (dexFile == null)
                {
                    throw new Exception(string.Format("classes.dex could not be extracted from {0} ", file.Name));
                }
                classesFile = dexFile;
            }
            else
            {
                classesFile = file.OdexFile;
            }

            Decompile(file.Name, classesFile, file.ClassesFolder, file.IgnoreDecompileErrors, file.Project);
            if (dexFile != null)
            {
                FolderUtility.DeleteDirectory(dexFile);
            }
        }
コード例 #7
0
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as IProjectFile;

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

            string relativePath = file.RelativePath;

            MessageEngine.AddInformation(this, string.Format("Adding {0} to update.zip", relativePath));
            _zipFile.Add(file.FileSystemPath, relativePath, CompressionType.Deflate);
        }
コード例 #8
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 (!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)));
            }
        }
コード例 #9
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));
            }

            if (!file.HasOdexFile)
            {
                return;
            }
            if (file.ContainsClassesDex)
            {
                MessageEngine.AddInformation(this, string.Format("{0} are already deodexed", file.Name));
                return;
            }

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

            if (!file.IsDeCompiled)
            {
                Directory.CreateDirectory(file.ClassesFolder);
                Decompile(file.Name, file.OdexFile, file.ClassesFolder, file.IgnoreDecompileErrors, file.Project);
            }

            if (!file.IsDeCompiled)
            {
                return;
            }
            Recompile(file.FileSystemPath, file.ClassesFolder, file.Project);
            file.Recompiled();
        }
コード例 #10
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 (file.IsDeCoded)
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Decoding resources for {0}", file.Name));

            InstallFrameworkIfMissing(file);

            var ep        = new ExecuteProgram((message) => MessageEngine.AddInformation(this, message));
            var arguments = new StringBuilder();

            arguments.Append("-jar \"").Append(_apkToolFile).Append("\"");
            if (_verbose)
            {
                arguments.Append(" -v");
            }
            arguments.Append(" d -s -f -t ").Append(file.Project.Properties.ApkToolFrameWorkTag);
            arguments.Append(" \"").Append(file.FileSystemPath).Append("\"");
            arguments.Append(" \"").Append(file.ResourceFolder).Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(_apkToolFile)) != 0)
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_apkToolFile)));
            }
        }
コード例 #11
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));
            }

            if (!file.IsDeCompiled)
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Recompiling classes for {0}", file.Name));

            Recompile(file.FileSystemPath, file.ClassesFolder, file.Project);
            file.Recompiled();
        }
コード例 #12
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));
            }

            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)));
            }
        }
コード例 #13
0
        protected void Decompile(string name, string classesFile, string outputFolder, bool ignoreDecompileErrors, CrcsProject project)
        {
            var ep = new ExecuteProgram();

            string locationOfDependencies = GetLocationOfDependencies(project);
            var    apiLevel = project.Properties.ApiLevel;

            bool decompiled = false;
            bool useIgnoreDecompileErrorsFlag = false;

            while (!decompiled)
            {
                string additionalDependencies = project.GetAdditionalDependencies(name).Aggregate("",
                                                                                                  (current, dependency)
                                                                                                  =>
                                                                                                  current +
                                                                                                  (":" + dependency));
                if (additionalDependencies.Length > 0)
                {
                    additionalDependencies = " -c " + additionalDependencies;
                }

                var arguments = new StringBuilder();
                arguments.Append("-Xmx512m -jar \"").Append(_baksmaliFile).Append("\"");
                arguments.Append(locationOfDependencies);
                arguments.Append(" -o \"").Append(outputFolder).Append("\"");
                if (useIgnoreDecompileErrorsFlag)
                {
                    arguments.Append(" -I");
                }
                arguments.Append(" -l -s");
                arguments.Append(additionalDependencies);
                if ((Path.GetExtension(classesFile) ?? "").ToUpperInvariant() == ".ODEX")
                {
                    arguments.Append(" -x");
                }
                arguments.Append(" \"").Append(classesFile).Append("\"");
                if (_useBaksmaliApiLevel)
                {
                    arguments.Append(" -a ").Append(apiLevel);
                }
                if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(classesFile)) == 0)
                {
                    if (useIgnoreDecompileErrorsFlag)
                    {
                        MessageEngine.AddInformation(this, ep.Output);
                    }
                    decompiled = true;
                }
                else
                {
                    if (!FindMissingDependency(name, project, ep.Output))
                    {
                        if (ignoreDecompileErrors)
                        {
                            useIgnoreDecompileErrorsFlag = true;
                        }
                        else
                        {
                            throw ep.CreateException(Path.GetFileName(_baksmaliFile));
                        }
                    }
                }
            }
        }
コード例 #14
0
        private static void Main(string[] args)
        {
            var p = (int)Environment.OSVersion.Platform;

            PlatformIsUnix = ((p == 4) || (p == 6) || (p == 128)) ? true : false;
            RunningMono    = (Type.GetType("Mono.Runtime") != null) ? true : false;

            //The first argument for devenv is usually a solution file or project file.
            //You can also use any other file as the first argument if you want to have the
            //file open automatically in an editor. When you enter a project file, the IDE
            //looks for an .sln file with the same base name as the project file in the
            //parent directory for the project file. If no such .sln file exists, then the
            //IDE looks for a single .sln file that references the project. If no such single
            //.sln file exists, then the IDE creates an unsaved solution with a default .sln
            //file name that has the same base name as the project file.
            try
            {
                string name        = Application.ProductName;
                string path        = Path.Combine(CrcsSettings.Current.AppDataPath, "Logfiles");
                var    logFileName = Settings.Default.LogFileName;
                if (!string.IsNullOrWhiteSpace(logFileName))
                {
                    name = Path.GetFileNameWithoutExtension(logFileName) ?? name;
                    path = Path.GetDirectoryName(logFileName) ?? path;
                }
                var fileMessageConsumer = new FileMessageConsumer(name.Replace(" ", "_"), path, Settings.Default.LogFileMaxSize, Settings.Default.LogFileDateTimeFormat);
                LogFileName = fileMessageConsumer.FileName;
                MessageEngine.AttachConsumer(fileMessageConsumer);
                if (CrcsSettings.Current.JavaFile == null)
                {
                    MessageBox.Show("Java was not found by the application\r\nIf it is not insalled install it.\r\nIf it is installed, you can set the path manually in the file CrcStudio.exe.config\r\nor add it to system path environment variable");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            try
            {
                string fileSystemPath = null;
                if (args.Length > 0)
                {
                    fileSystemPath = string.Join(" ", args);
                    if (!File.Exists(fileSystemPath))
                    {
                        MessageBox.Show("File not found", "Custom Rom Creator Studio");
                        return;
                    }
                    var extension = (Path.GetExtension(fileSystemPath) ?? "").ToUpperInvariant();
                    if (extension != ".RSPROJ" && extension != ".RSSLN")
                    {
                        var clds = IpcCommunication.GetObjects <CommandLineDispatcher>().ToArray();
                        if (clds.Length > 0)
                        {
                            foreach (var cld in clds)
                            {
                                if (cld.ContainsFile(fileSystemPath))
                                {
                                    ApplicationToForeground(Process.GetProcessById(cld.GetProcessId()).MainWindowHandle);
                                    cld.OpenFile(fileSystemPath);
                                    return;
                                }
                            }
                            ApplicationToForeground(Process.GetProcessById(clds[0].GetProcessId()).MainWindowHandle);
                            clds[0].OpenFile(fileSystemPath);
                            return;
                        }
                    }
                }
                IpcCommunication.AddIpcObject(typeof(CommandLineDispatcher));
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                var form = new MainForm(fileSystemPath);
                MessageEngine.Initialize(form);
                MessageEngine.AddInformation(null, "Application started");
                MessageEngine.AddDebug(null, "Path to java.exe: " + CrcsSettings.Current.JavaFile);
                Application.Run(form);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }