public override void OnPageShow() { modInfo = new ModInfo(Application.StartupPath + "/Mods/" + PrefsManager.GetInstance().GetPrefString("SelectedMod") + "/ModInfo.ini"); string workspace = Application.StartupPath + "/Workspace"; string[] allFiles = null; if (PrefsManager.GetInstance().GetPrefString("ZipPackagingMode") == "All") { string[] files = Directory.GetFiles(Application.StartupPath + "/Workspace", "*.*", SearchOption.AllDirectories); allFiles = new string[files.Length]; int length = (Application.StartupPath + "/Workspace").Length; for (int i = 0; i < files.Length; i++) { files[i] = files[i].Substring(length).Replace("\\", "/"); } files.CopyTo(allFiles, 0); } else { allFiles = new string[modInfo.ModifiedFiles.Length]; modInfo.ModifiedFiles.CopyTo(allFiles, 0); } foreach (string file in allFiles) { fileListBox.Items.Add(file, true); } updatePatchInfo(); }
public override void OnPageShow() { modList.Items.Clear(); modList.ClearSelected(); string[] modInfoFiles = null; try { modInfoFiles = Directory.GetFiles(Environment.CurrentDirectory + "/Mods", "ModInfo.ini", SearchOption.AllDirectories); } catch { } if (modInfoFiles == null) { MessageBox.Show("설치된 모드가 없습니다!", "MM!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ModInfo modInfo; string modScriptPath; foreach (string modInfoFile in modInfoFiles) { modScriptPath = new FileInfo(modInfoFile).Directory.ToString() + "/ModScript.mmm"; if (File.Exists(modScriptPath)) { modInfo = new ModInfo(modInfoFile); modList.Items.Add(modInfo); } } }
public override void OnPageShow() { SetButtonStatus(NavigationButton.Prev, true); SetButtonStatus(NavigationButton.Next, false); modList.Items.Clear(); modList.ClearSelected(); modInfoText.Text = ""; string[] modInfoFiles = null; try { modInfoFiles = Directory.GetFiles(Environment.CurrentDirectory + "/Mods", "ModInfo.ini", SearchOption.AllDirectories); } catch { } if (modInfoFiles == null) { MessageBox.Show("설치된 모드가 없습니다!", "MM!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ModInfo modInfo; string modScriptPath; foreach (string modInfoFile in modInfoFiles) { modScriptPath = new FileInfo(modInfoFile).Directory.ToString() + "/ModScript.mmm"; if (File.Exists(modScriptPath)) { modInfo = new ModInfo(modInfoFile); if (File.Exists(Application.StartupPath + "/Mods/" + modInfo.DirName + "/ModInfo.ini") && File.Exists(Application.StartupPath + "/Mods/" + modInfo.DirName + "/ModScript.mmm")) { modList.Items.Add(modInfo); } } } PrefsManager prefs = PrefsManager.GetInstance(); if ( prefs.GetPrefString("AutopilotMode") == "true") { string currentMode = prefs.GetPrefStringArray("AutopilotMods")[prefs.GetPrefInt("AutopilotCurrent")]; int i = 0; foreach (ModInfo item in modList.Items) { if (item.DirName == currentMode) { modList.SelectedIndex = i; break; } i++; } } }
public override void OnPageShow() { SetButtonStatus(NavigationButton.Prev, true); SetButtonStatus(NavigationButton.Next, false); modInfo = new ModInfo(Application.StartupPath + "/Mods/" + PrefsManager.GetInstance().GetPrefString("SelectedMod") + "/ModInfo.ini"); modTitleLabel.Text = modInfo.Title + " " + modInfo.Version + " - by " + modInfo.Author + "\r\n\r\n"; CheckFiles(); }
public override void OnPageShow() { debugTextBox.Text = ""; fileListBox.Items.Clear(); adbMode = PrefsManager.GetInstance().GetPrefString("AdbMode"); if (adbMode == "pull") { button_PullPushFiles.Text = lang.GetString("Pull_Files"); } else { button_PullPushFiles.Text = lang.GetString("Push_Files"); } ProcessStartInfo adbStartInfo = new ProcessStartInfo(Application.StartupPath + "/bin/adb.exe"); adbStartInfo.Arguments = "devices"; adbStartInfo.UseShellExecute = false; adbStartInfo.RedirectStandardOutput = true; adbStartInfo.CreateNoWindow = true; Process adbDaemon = Process.Start(adbStartInfo); ModInfo modInfo = new ModInfo(Application.StartupPath + "/Mods/" + PrefsManager.GetInstance().GetPrefString("SelectedMod") + "/ModInfo.ini"); string workspace = Application.StartupPath + "/Workspace"; string[] allFiles = null; if (adbMode == "pull") { allFiles = new string[modInfo.RequiredFiles.Length + modInfo.ModifiedFiles.Length]; modInfo.ModifiedFiles.CopyTo(allFiles, 0); modInfo.RequiredFiles.CopyTo(allFiles, modInfo.ModifiedFiles.Length); } else { if (PrefsManager.GetInstance().GetPrefString("AdbFileMode") == "All") { string[] files = Directory.GetFiles(Application.StartupPath + "/Workspace", "*.*", SearchOption.AllDirectories); allFiles = new string[files.Length]; int length = (Application.StartupPath + "/Workspace").Length; for (int i = 0; i < files.Length; i++) { files[i] = files[i].Substring(length).Replace("\\", "/"); } files.CopyTo(allFiles, 0); } else { allFiles = new string[modInfo.ModifiedFiles.Length]; modInfo.ModifiedFiles.CopyTo(allFiles, 0); } } List<String> allFilesList = new List<string>(); foreach (string file in allFiles) { if (!allFilesList.Contains(file)) { allFilesList.Add(file); } } allFiles = allFilesList.ToArray(); foreach (string file in allFiles) { bool chk = !File.Exists(workspace + "/" + file); if ( adbMode == "push" ) chk = true; if (file != "") { fileListBox.Items.Add(file, chk); } } }
private void parseScript() { string resultString = ""; string javaDir = ""; string system32Directory = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32"); if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess) { // For 32-bit processes on 64-bit systems, %windir%\system32 folder // can only be accessed by specifying %windir%\sysnative folder. system32Directory = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "sysnative"); } if (File.Exists(system32Directory + "/java.exe")) { javaDir = system32Directory + "/java.exe"; } else if (File.Exists(Environment.SystemDirectory + "/java.exe")) { javaDir = Environment.SystemDirectory + "/java.exe"; } else if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "/system32/java.exe")) { javaDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "/system32/java.exe"; } else if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "/syswow64/java.exe")) { javaDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "/syswow64/java.exe"; } else { javaDir = "java.exe"; resultString = lang.GetString("Missing_Java_Runtime"); } try { System.IO.Directory.Delete(Application.StartupPath + "/Temp", true); } catch { //do nothing, it's fine. } try { System.IO.Directory.Delete(Application.StartupPath + "/Out", true); } catch { //do nothing, it's fine. } setProgressBar(0); ModInfo modInfo = new ModInfo(Application.StartupPath + "/Mods/" + PrefsManager.GetInstance().GetPrefString("SelectedMod") + "/ModInfo.ini"); string modScriptPath = Application.StartupPath + "/Mods/" + PrefsManager.GetInstance().GetPrefString("SelectedMod") + "/ModScript.mmm"; string modLuaPath = Application.StartupPath + "/Mods/" + PrefsManager.GetInstance().GetPrefString("SelectedMod") + "/ModScript.lua"; string modPath = Application.StartupPath + "/Mods/" + PrefsManager.GetInstance().GetPrefString("SelectedMod"); StreamReader streamReader = new StreamReader(modScriptPath, Encoding.GetEncoding(949)); string line, command; string[] split, arg = null; string filePathDirOnly = ""; string[] _split; ZipFile zipFile = null; foreach (string file in modInfo.RequiredFiles) { if (file == "/system/framework/framework-res.apk" || file == "system/framework/framework-res.apk") { string frameworkPath = Application.StartupPath + "/Workspace/system/framework/framework-res.apk"; if (File.Exists(frameworkPath)) { RunProgram(javaDir, "-Xms32m -Xmx1024m -jar apktool.jar if \"" + frameworkPath + "\"", Application.StartupPath + "/Bin"); } } } bool useNewParser = false; #region OldParser while ((line = streamReader.ReadLine()) != null) { if (line == "#MM_USE_LUA_SCRIPT") { useNewParser = true; break; } if (resultString != "") { break; } filePathDirOnly = ""; split = line.Split('|'); if (split.Length > 0) { command = split[0]; if (split.Length > 1) { split[1] = split[1].Replace("\\,", "{COMMA}"); arg = split[1].Split(','); for (int i = 0; i < arg.Length; i++) { arg[i] = parseLine(arg[i]); } } } else { command = line; } switch (command) { case "IF": if (arg[0] == arg[1]) varStorage[arg[2]] = arg[3]; break; case "ASK": string value = ""; if (InputBox("MM!", arg[0], ref value) == DialogResult.OK) { varStorage[arg[1]] = value; } break; case "ASK_YESNO": DialogResult _result = MessageBox.Show(arg[0], "MM!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (_result == System.Windows.Forms.DialogResult.Yes) { varStorage[arg[1]] = "Yes"; } else { varStorage[arg[1]] = "No"; } break; case "ZIP_OPEN": if (!File.Exists(Application.StartupPath + "/" + arg[0])) { debugOut(String.Format(lang.GetString("Debug_ZIP_OPEN"), Application.StartupPath + "/" + arg[0])); continue; } zipFile = ZipFile.Read(Application.StartupPath + "/" + arg[0]); Thread.Sleep(1000); break; case "ZIP_EXTRACT": if (zipFile == null) { debugOut(lang.GetString("Debug_ZIP_EXTRACT")); continue; } zipFile.ExtractAll(Application.StartupPath + "/" + arg[0], ExtractExistingFileAction.OverwriteSilently); Thread.Sleep(1000); break; case "ZIP_ADDFILE": if (!File.Exists(Application.StartupPath + "/" + arg[0])) { debugOut(String.Format(lang.GetString("ZIP_ADDFILE"), Application.StartupPath + "/" + arg[0])); continue; } zipFile.AddFile(arg[0], arg[1]); break; case "ZIP_ADDDIRECTORY": if (!Directory.Exists(Application.StartupPath + "/" + arg[0])) { debugOut(String.Format(lang.GetString("ZIP_ADDDIRECTORY"), Application.StartupPath + "/" + arg[0])); continue; } zipFile.AddDirectory(arg[0], arg[1]); break; case "ZIP_UPDATE": if (!File.Exists(Application.StartupPath + "/" + arg[0])) { debugOut(String.Format(lang.GetString("Debug_ZIP_UPDATE"), Application.StartupPath + "/" + arg[0])); continue; } zipFile.UpdateFile(arg[0], arg[1]); break; case "ZIP_SAVE": zipFile.Save(arg[0]); Thread.Sleep(1000); break; case "COPY": if (!File.Exists(Application.StartupPath + "/" + arg[0])) { debugOut(String.Format(lang.GetString("Debug_COPY"), Application.StartupPath + "/" + arg[0])); continue; } MyExtensions.CreateDirectory(new DirectoryInfo(Directory.GetParent(Application.StartupPath + "/" + arg[1]).ToString())); File.Copy(Application.StartupPath + "/" + arg[0], Application.StartupPath + "/" + arg[1], true); Thread.Sleep(1000); break; case "DEBUG_DONTDELETETEMP": break; case "SET": varStorage[arg[0]] = arg[1]; break; case "OPEN": if (!File.Exists(Application.StartupPath + "/" + arg[1])) { debugOut(String.Format(lang.GetString("Debug_OPEN"), Application.StartupPath + "/" + arg[1])); continue; } using (StreamReader strReader = new StreamReader(Application.StartupPath + "/" + arg[1])) { varStorage[arg[0]] = strReader.ReadToEnd(); } break; case "PARSE": varStorage[arg[0]] = parseLine(varStorage[arg[0]]); break; case "SAVE": //MyExtensions.CreateDirectory(new DirectoryInfo(Directory.GetParent(Application.StartupPath + "/" + arg[1]).ToString())); using (StreamWriter strWriter = new StreamWriter(Application.StartupPath + "/" + arg[1])) { strWriter.Write(varStorage[arg[0]]); } Thread.Sleep(1000); break; case "STRING_TRIM": varStorage[arg[0]] = varStorage[arg[0]].Trim(); break; case "STRING_REPLACE": varStorage[arg[0]] = varStorage[arg[0]].Replace(arg[1], arg[2]); break; case "SEARCHANDREPLACE": using (StringReader stringReader = new StringReader(varStorage[arg[0]])) { bool searchIgnore = false; StringWriter stringWriter = new StringWriter(); string _line; while ((_line = stringReader.ReadLine()) != null) { if (!searchIgnore && Regex.IsMatch(_line, Regex.Escape(arg[1]))) { searchIgnore = true; stringWriter.WriteLine(arg[2]); } if (!searchIgnore) stringWriter.WriteLine(_line); if (searchIgnore && Regex.IsMatch(_line, Regex.Escape(arg[3]))) { searchIgnore = false; } } varStorage[arg[0]] = stringWriter.ToString(); } break; case "SEARCH": using (StringReader stringReader = new StringReader(varStorage[arg[0]])) { bool searchFound = false; StringWriter stringWriter = new StringWriter(); string _line; while ((_line = stringReader.ReadLine()) != null) { if (!searchFound && Regex.IsMatch(_line, Regex.Escape(arg[1]))) { searchFound = true; varStorage[arg[3] + "_SearchHeader"] = _line; } if (searchFound) stringWriter.WriteLine(_line); if (searchFound && Regex.IsMatch(_line, Regex.Escape(arg[2]))) { searchFound = false; varStorage[arg[3] + "_SearchFooter"] = _line; } } varStorage[arg[3]] = stringWriter.ToString(); } break; case "PRINT": debugOut(arg[0]); break; case "EXTRACT_WITHRES": MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Temp")); resultString = RunProgram(javaDir, "-Xms32m -Xmx1024m -jar apktool.jar d -f " + "\"../Workspace" + arg[0] + "\"" + " " + "\"../Temp" + arg[0] + "\"", Application.StartupPath + "/Bin"); Thread.Sleep(1000); break; case "EXTRACT_F": MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Temp")); resultString = RunProgram(javaDir, "-Xms32m -Xmx1024m -jar apktool.jar d -f -r " + "\"../Workspace" + arg[0] + "\"" + " " + "\"../Temp" + arg[0] + "\"", Application.StartupPath + "/Bin"); Thread.Sleep(1000); break; case "EXTRACT": MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Temp")); resultString = RunProgram(javaDir, "-Xms32m -Xmx1024m -jar apktool.jar d -f -r " + "\"../Workspace" + arg[0] + "\"" + " " + "\"../Temp" + arg[0] + "\"", Application.StartupPath + "/Bin"); Thread.Sleep(1000); break; case "EXTRACT_BIG": MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Temp")); resultString = RunProgram(javaDir, "-Xms32m -Xmx1024m -jar apktool.jar d -f -r " + "\"../Workspace" + arg[0] + "\"" + " " + "\"../Temp" + arg[0] + "\"", Application.StartupPath + "/Bin"); Console.WriteLine("-Xms32m -Xmx1024m -jar apktool.jar d -f -r " + "\"../Workspace" + arg[0] + "\"" + " " + "\"../Temp" + arg[0] + "\"", Application.StartupPath + "/Bin"); Thread.Sleep(1000); break; case "BUILD": MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Temp/Unsigned")); resultString = RunProgram(javaDir, "-Xms32m -Xmx1024m -jar apktool.jar b " + "\"../Temp" + arg[0] + "\"" + " " + "\"../Temp/Unsigned" + arg[0] + "\"", Application.StartupPath + "/Bin"); Thread.Sleep(1000); break; case "BUILD_BIG": MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Temp/Unsigned")); resultString = RunProgram(javaDir, "-Xms32m -Xmx1024m -jar apktool.jar b " + "\"../Temp" + arg[0] + "\"" + " " + "\"../Temp/Unsigned" + arg[0] + "\"", Application.StartupPath + "/Bin"); Thread.Sleep(1000); break; case "SIGN": if (!File.Exists(Application.StartupPath + "/Temp/Unsigned" + arg[0])) { debugOut(String.Format(lang.GetString("Debug_SIGN"), Application.StartupPath + "/Temp/Unsigned" + arg[0])); continue; } MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Out")); filePathDirOnly = ""; _split = arg[0].Split('/'); for (int j = 0; j < _split.Length - 1; j++) { filePathDirOnly += _split[j] + '/'; } MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Out/" + filePathDirOnly)); resultString = RunProgram(javaDir, "-jar signapk.jar testkey.x509.pem testkey.pk8 " + "\"../Temp/Unsigned" + arg[0] + "\" " + "\"../Out" + arg[0] + "\"", Application.StartupPath + "/Bin"); Thread.Sleep(1000); break; case "COPYSIGN": if (!File.Exists(Application.StartupPath + "/Temp/Unsigned" + arg[0])) { debugOut(String.Format(lang.GetString("Debug_COPYSIGN"), Application.StartupPath + "/Temp/Unsigned" + arg[0])); continue; } MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Temp")); filePathDirOnly = ""; _split = arg[0].Split('/'); for (int j = 0; j < _split.Length - 1; j++) { filePathDirOnly += _split[j] + '/'; } MyExtensions.CreateDirectory(new DirectoryInfo(Application.StartupPath + "/Out/" + filePathDirOnly)); using (ZipFile originalZip = ZipFile.Read(Application.StartupPath + "/Workspace" + arg[0])) { originalZip.ExtractSelectedEntries("name = AndroidManifest.xml", "", Application.StartupPath + "/Temp", ExtractExistingFileAction.OverwriteSilently); originalZip.ExtractSelectedEntries("name = CERT.RSA", "META-INF/", Application.StartupPath + "/Temp", ExtractExistingFileAction.OverwriteSilently); originalZip.ExtractSelectedEntries("name = CERT.SF", "META-INF/", Application.StartupPath + "/Temp", ExtractExistingFileAction.OverwriteSilently); originalZip.ExtractSelectedEntries("name = MANIFEST.MF", "META-INF/", Application.StartupPath + "/Temp", ExtractExistingFileAction.OverwriteSilently); } using (ZipFile newZip = ZipFile.Read(Application.StartupPath + "/Temp/Unsigned" + arg[0])) { newZip.UpdateFile(Application.StartupPath + "/Temp/AndroidManifest.xml", ""); newZip.UpdateFile(Application.StartupPath + "/Temp/META-INF/CERT.RSA", "META-INF/"); newZip.UpdateFile(Application.StartupPath + "/Temp/META-INF/CERT.SF", "META-INF/"); newZip.UpdateFile(Application.StartupPath + "/Temp/META-INF/MANIFEST.MF", "META-INF/"); newZip.Save(Application.StartupPath + "/Out" + arg[0]); } /*resultString = RunProgram("java", "-jar signapk.jar testkey.x509.pem testkey.pk8 " + "\"../Temp/Unsigned" + arg[0] + "\" " + "\"../Out" + arg[0] + "\"", Application.StartupPath + "/Bin");*/ Thread.Sleep(1000); break; case "RUN": if (!File.Exists(modPath + "/" + arg[0]) && !File.Exists(modPath + "/" + arg[0] + ".exe")) { debugOut(String.Format(lang.GetString("Debug_RUN"), modPath + "/" + arg[0])); continue; } resultString = RunProgram(modPath + "/" + arg[0], arg[1], modPath); Thread.Sleep(1000); break; case "COPYRES": if (File.Exists(Application.StartupPath + "/Workspace/system/framework/framework-res.apk")) { try { File.Copy(Application.StartupPath + "/Workspace/system/framework/framework-res.apk", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/apktool/framework/1.apk", true); } catch { } } else { resultString = String.Format(lang.GetString("File_Not_Found"), "/system/framework/framework-res.apk"); } break; case "DELRES": if (File.Exists(Application.StartupPath + "/Workspace/system/framework/framework-res.apk")) { File.Delete(Application.StartupPath + "/Workspace/system/framework/framework-res.apk"); } break; case "SETPROGRESS": setProgressBar(Convert.ToInt16(arg[0])); break; case "CHECKVERSION": int checkVersion = Convert.ToInt16(arg[0].Replace("v", "").Replace(".", "")); int thisVersion = Convert.ToInt16(PrefsManager.GetInstance().GetPrefString("Version").Replace("v", "").Replace(".", "")); if (checkVersion > thisVersion) { resultString = String.Format(lang.GetString("Version_Required"), arg[0]); } break; } } #endregion if (useNewParser == true) { MMScriptFunctions functions = new MMScriptFunctions(); PrefsManager prefs = PrefsManager.GetInstance(); prefs.SetPrefString("JavaDir", javaDir); prefs.SetPrefBool("DebugMode", false); MMScriptParser parser = new MMScriptParser(modLuaPath, functions); parser.Parse(); } if (resultString != "") { StringReader stringReader = new StringReader(resultString); debugOut(lang.GetString("Error_Caused")); while ((line = stringReader.ReadLine()) != null) { debugOut(line); } } else { debugOut(lang.GetString("Script_End")); if (!PrefsManager.GetInstance().GetPrefBool("DebugMode")) { try { System.IO.Directory.Delete(Application.StartupPath + "/Temp", true); } catch { //do nothing, it's fine. } } } int counter = 0; foreach (string modFile in modInfo.ModifiedFiles) { if (!File.Exists(Application.StartupPath + "/Out" + modFile)) { debugOut(String.Format(lang.GetString("File_Output_Not_Found"), modFile)); counter++; } } if (counter == 0) { if (!PrefsManager.GetInstance().GetPrefBool("DebugMode")) { try { System.IO.Directory.Delete(Application.StartupPath + "/Temp", true); } catch { //do nothing, it's fine. } } SetButtonStatusFromThread(NavigationButton.Next, true); } else { debugOut(lang.GetString("Script_Has_Problem")); SetButtonStatusFromThread(NavigationButton.Prev, true); SetButtonStatusFromThread(NavigationButton.Next, false); } streamReader.Close(); }