just write the code, make a record
Using ionic.zip;using system;using system.collections.generic;using system.diagnostics;using System.IO;using System.linq;using system.text;using System.threading.tasks;namespace apicloudmodulepackage{class Program {s Tatic string TempPath; Static Toolconfig Toolconfig; static void Main (string[] args) {TempPath = Path.gettemppath () + Guid.NewGuid (). ToString ("N") + "\ \"; if (directory.exists (temppath) = = False) {directory.createdirectory (TempPath); } toolconfig = Newtonsoft.json.jsonconvert.deserializeobject<toolconfig> (File.readalltext (AppDomain.Curr Entdomain.basedirectory + "Projects.json")); try {foreach (Projectconfig project in toolconfig.projects) { Compile Jar Jarproject (project); } console.write ("Need to generate a ZIP file for the module now?"} [y/n]:\r\n\r\n "); WHile (True) {var keyresult = Console.readkey (); if (Keyresult.key = = consolekey.y) {//make zip file fr Om Module folder foreach (Var modulefolder in toolconfig.modules) { Makezip (Getpathfromconfig (Modulefolder)); Console.WriteLine ("Packaged output:" + Modulefolder + ". zip"); } break; } else if (Keyresult.key = = CONSOLEKEY.N) {Process.getcurren Tprocess (). Kill (); }} Console.WriteLine ("Package Complete! Press any key to exit "); } catch (Exception ex) {Console.WriteLine (ex. Message); } try {Directory.delete (TempPath, true); } catch {} console.readkey (); } static void Makezip (String folder) {string Zipfilepath = Path.getdirectoryname (folder) + "\ \" + path.getfilename (folder) + ". zip"; if (file.exists (Zipfilepath)) File.delete (Zipfilepath); using (ZipFile zip = new ZipFile (Zipfilepath)) {String root = Path.getfilename (folder); Zip. Adddirectorybyname (root); Zip. Adddirectory (folder, root); Zip. Save (); }} static void Jarproject (Projectconfig project) {Console.WriteLine ("Compiling" + proj Ect.sourcefolder); String srcpath = Getpathfromconfig (Project.sourcefolder); Create Temp folder String TempFolder = TempPath + Guid.NewGuid (). ToString ("N") + "\ \"; String classtempfolder = TempFolder + Guid.NewGuid (). ToString ("N") +"\\"; String jardstfolder = TempFolder + "jar\\"; if (directory.exists (jardstfolder) = = False) {directory.createdirectory (Jardstfolder); } if (directory.exists (classtempfolder) = = False) {Directory.CreateDirectory (CLA Sstempfolder); } list<string> javafiles = new list<string> (); GetFiles (Javafiles, Srcpath, "*.java"); Copy Java files to temp folder string encoding = NULL; foreach (String javafile in Javafiles) {if (encoding = = null) { var encode = Getfileencodetype (javafile); if (encode = = System.Text.Encoding.UTF8) {Encoding = "utf-8"; } else {encoding = "GBK"; } } File.Copy (javafile, TempFolder + path.getfilename (javafile), true); } StringBuilder libjars = new StringBuilder (); StringBuilder proguardlibjars = new StringBuilder (); if (!string. IsNullOrEmpty (Project.libpath)) {//make sure link necessary jar files list< string> libfiles = new list<string> (); GetFiles (Libfiles, Getpathfromconfig (Project.libpath), "*.jar"); if (libfiles. Count > 0) {libjars.append ("-CP"); foreach (Var libfile in libfiles) {libjars.append (' \ "'); Libjars.append (Libfile); Libjars.append (' \ '); Libjars.append (';'); Proguardlibjars.append ("-libraryjars"); Proguardlibjars.append (' \ '); prOguardlibjars.append (Libfile); Proguardlibjars.append (' \ '); }}} ProcessStartInfo Prostartinfo = new ProcessStartInfo ("Javac"); Prostartinfo.arguments = $ "-xlint:unchecked-xlint:deprecation-encoding {encoding}-bootclasspath Android.jar {Libjars}-d {classtempfolder} {Tempfolder}*.java "; Prostartinfo.useshellexecute = false; Process process = Process.Start (prostartinfo); Process. WaitForExit (); if (true) {//build jar, jar file actually is zip file using (ZipFile zip = new Zi PFile ($ "{Jardstfolder}result.jar")) {zip. Adddirectory (Classtempfolder); var content = @ "manifest-version:1.0created-by:1.8.0_40 (Oracle Corporation)"; byte[] bs = System.Text.Encoding.UTF8.GetBytes (content); Zip. AddEntry ("Meta-inf/manifest. MF ", BS); Zip. Save (); }} else {////here is a jar file generated with the JAR program//list<string> class Files = new list<string> (); GetFiles (Classfiles, TempFolder, "*.class"); foreach (String classfile in Classfiles)//{//File.Copy (Classfile, Jardstfolder + Pat H.getfilename (Classfile), true); }//prostartinfo = new ProcessStartInfo ("jar"); Prostartinfo.arguments = $ "CVF {jardstfolder}result.jar {jardstfolder}*.class"; Prostartinfo.useshellexecute = false; Process = Process.Start (prostartinfo); Process. WaitForExit (); }//Obfuscation compile if (!string. IsNullOrEmpty (Project.proguardconfigfile)) {Console.WriteLine ("Confusing Code ..."); Prostartinfo = new ProcessStartInfo ("JAva "); Prostartinfo.arguments = $ "-jar Proguard.jar @{project.proguardconfigfile}-injars {jardstfolder}result.jar-outjars { Jardstfolder}result2.jar-libraryjars Android.jar {proguardlibjars} "; Prostartinfo.useshellexecute = false; Process = Process.Start (prostartinfo); Process. WaitForExit (); if (file.exists ($ "{Jardstfolder}result2.jar") = = false) throw new Exception (Project.sourcefolder + "code mixed Xiao Error "); File.delete ($ "{Jardstfolder}result.jar"); File.move ($ "{Jardstfolder}result2.jar", $ "{Jardstfolder}result.jar"); } if (File.exists ($ "{Jardstfolder}result.jar") = = false) throw new Exception ("compile" + PROJECT.SOURC EFolder + "Failed! "); Copy jar to destination foreach (Var dstpath in project.builddestinations) {Stri ng destination = Getpathfromconfig (Dstpath); File.Copy ($ "{jarDstfolder}result.jar ", destination, true); Console.WriteLine ($ "maked {destination}"); }} static System.Text.Encoding Getfileencodetype (string filename) {using (System.IO.File Stream fs = new System.IO.FileStream (filename, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { System.IO.BinaryReader br = new System.IO.BinaryReader (FS); byte[] buffer = br. Readbytes (2); if (Buffer[0] >= 0xEF) {if (buffer[0] = = 0xEF && buffer[1] = = 0xBB) {return System.Text.Encoding.UTF8; } else if (buffer[0] = = 0xFE && buffer[1] = = 0xFF) { return System.Text.Encoding.BigEndianUnicode; } else if (buffer[0] = = 0xFF && buffer[1] = = 0xFE) { return System.Text.Encoding.Unicode; } else {return System.Text.Encoding.Default; }} else {return System.Text.Encoding.Default; }}}} static string Getpathfromconfig (string path) {if (path[1] = = ': ') return path. Replace ("/", "\ \"); else {return AppDomain.CurrentDomain.BaseDirectory + path. Replace ("/", "\ \"); }} static void GetFiles (list<string> result, string folder, String pattern) { var files = directory.getfiles (folder, pattern); Result. AddRange (files); var dirs = directory.getdirectories (folder); foreach (var dir in dirs) {getFiles (result, dir, pattern); } } }}
Post a section to automatically compile Java and confuse the compiled code