Example #1
0
 private void AddModLoaderToApk(string apkFilename)
 {
     UpdateStatus("Adding the libmodloader.so file to the APK...");
     try
     {
         using (var apk = new ZipFileProvider(apkFilename, FileCacheMode.None, false, QuestomAssets.Utils.FileUtils.GetTempDirectory()))
         {
             using (var resStream = _context.Resources.OpenRawResource(Resource.Raw.libmodloader))
             {
                 using (var resStream64 = _context.Resources.OpenRawResource(Resource.Raw.libmodloader64))
                 {
                     if (apk.DirectoryExists(LIBMODLOADER_TARGET_FILE.GetDirectoryFwdSlash()))
                     {
                         if (apk.FileExists(LIBMODLOADER_TARGET_FILE))
                         {
                             apk.Delete(LIBMODLOADER_TARGET_FILE);
                             apk.Save();
                         }
                         apk.QueueWriteStream(LIBMODLOADER_TARGET_FILE, resStream, true, true);
                     }
                     if (apk.DirectoryExists(LIBMODLOADER64_TARGET_FILE.GetDirectoryFwdSlash()))
                     {
                         if (apk.FileExists(LIBMODLOADER64_TARGET_FILE))
                         {
                             apk.Delete(LIBMODLOADER64_TARGET_FILE);
                             apk.Save();
                         }
                         apk.QueueWriteStream(LIBMODLOADER64_TARGET_FILE, resStream64, true, true);
                     }
                     try
                     {
                         apk.Save();
                     } catch (IOException)
                     {
                         GC.Collect();
                         System.Threading.Thread.Sleep(1000);
                         apk.Save();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.LogErr("Error adding libmodloader.so to APK", ex);
         UpdateStatus("Error adding modloader to the APK!");
         throw new ModException("Error adding libmodloader.so to APK", ex);
     }
 }