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())) { apk.QueueWriteStream(LIBMODLOADER_TARGET_FILE, resStream, true, true); } if (apk.DirectoryExists(LIBMODLOADER64_TARGET_FILE.GetDirectoryFwdSlash())) { apk.QueueWriteStream(LIBMODLOADER64_TARGET_FILE, resStream64, true, true); } 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); } }
private void AddAndroidPermissions(string apkFilename, List <string> permissions) { if (permissions == null || permissions.Count < 1) { throw new ArgumentException("At least one permission must be specified to add."); } try { using (var apk = new ZipFileProvider(apkFilename, FileCacheMode.None, false, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { byte[] manifest = apk.Read("AndroidManifest.xml"); AxmlWriter writer = new WritePermissionAxmlWriter(permissions); AxmlReader reader = new AxmlReader(manifest); reader.Accept(writer); var outData = writer.ToByteArray(); apk.Write("AndroidManifest.xml", outData, true); apk.Save(); } } catch (Exception ex) { Log.LogErr("Exception trying to add permissions to AndroidManifest.xml", ex); throw; } }
private void ConfigurePdfJsZip(IApplicationBuilder app, IHostingEnvironment env) { var zipFile = Path.Combine(env.ContentRootPath, "pdfjs-1.9.426-dist.zip"); var provider = new ZipFileProvider(zipFile); app.UseStaticFiles(new StaticFileOptions { FileProvider = provider, RequestPath = "/pdfjs", // following are required for extension-less files ServeUnknownFileTypes = true, DefaultContentType = "text/plain" }); app.UseDirectoryBrowser(new DirectoryBrowserOptions { FileProvider = provider, RequestPath = "/pdfjs", }); //app.UseFileServer(new FileServerOptions() //{ // FileProvider = provider, // RequestPath = "/pdfjs", // EnableDirectoryBrowsing = true, //}); }
private bool IsApk64Bit(string apkFilename) { UpdateStatus("Checking if APK is 64-bit..."); try { using (var apk = new ZipFileProvider(apkFilename, FileCacheMode.None, true, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { if (apk.DirectoryExists(LIBMODLOADER64_TARGET_FILE.GetDirectoryFwdSlash())) { UpdateStatus("APK is 64 bit"); return(true); } if (apk.DirectoryExists(LIBMODLOADER_TARGET_FILE.GetDirectoryFwdSlash())) { UpdateStatus("APK is 32 bit"); return(false); } UpdateStatus("Can't find a libs folder for either 32 or 64 bit..."); throw new ModException("Unable to find library folder to determine 32 or 64 bit."); } } catch (Exception ex) { Log.LogErr("Error determining if APK is 64 bit!", ex); UpdateStatus("Unable to determine if APK is 32 or 64 bit!"); throw new ModException("Error determining if APK is 64 bit!", ex); } }
public void Main(string[] args) { var zip = new ZipFileProvider("Data/dogs.zip"); using (AgateSetup setup = new AgateSetup()) { setup.Initialize(true, false, false); if (setup.WasCanceled) { return; } DisplayWindow wind = DisplayWindow.CreateWindowed( "ZipFileProvider Tester", 800, 600, false); Surface surf = new Surface(zip, "dogs.png"); Surface surf2 = new Surface(zip, "bigpaddle.png"); Surface surf3 = new Surface(zip, "other/bg-bricks.png"); PixelBuffer pix = surf.ReadPixels(); while (wind.IsClosed == false) { Display.BeginFrame(); Display.Clear(Color.Blue); surf.Draw(); surf2.Draw(10, 490); surf3.Draw(100, 100); Display.EndFrame(); Core.KeepAlive(); } } }
/// <summary> /// Returns a file system implementation, which is assigned /// to the <see cref="TestContext.FileSystem"/> property. /// </summary> /// <param name="localTestFolder">The temporary test folder that is /// used by the context. This is actually just the <see cref="TestContext.LocalTestRoot"/> /// reference.</param> protected override IFileSystemProvider InitFileSystem(DirectoryInfo localTestFolder) { //init empty zip file ZipFilePath = Path.Combine(localTestFolder.FullName, "TestArchive.zip"); var zip = new ZipFile(ZipFilePath); zip.Save(); zip.Dispose(); //init transfer stores var downloadTransferStore = new TestTransferStore<ZipDownloadTransfer>(); var uploadTransferStore = new TestTransferStore<ZipUploadTransfer>(); //init configuration var tempFactory = new TempFileStreamFactory(LocalTestRoot.FullName); var zipFile = new FileInfo(ZipFilePath); var configuration = new ZipFileSystemConfiguration(zipFile, tempFactory); configuration.RootName = "Test Root"; configuration.DownloadStore = downloadTransferStore; configuration.UploadStore = uploadTransferStore; configuration.DownloadTokenExpirationTime = TimeSpan.FromHours(24); configuration.UploadTokenExpirationTime = TimeSpan.FromHours(24); configuration.DefaultDownloadBlockSize = 32768; configuration.MaxDownloadBlockSize = 32768 * 2; configuration.MaxUploadBlockSize = 32768 * 4; configuration.MaxUploadFileSize = (long)1024 * 1024 * 2048; //2GB limit //create provider Provider = new ZipFileProvider(configuration); return Provider; }
public void GetFileInfo_Given_Root_Dont_Exist() { var provider = new ZipFileProvider(TestData.No_Data_Zip_File); var result = provider.GetFileInfo("/"); Assert.False(result.Exists, "Root returned for file."); }
public void GetFileInfo_For_Real_Sub_Folder_Dont_Exist(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetFileInfo("/folder with files/sub folder"); Assert.False(result.Exists, "Folder exists."); }
public void GetFileInfo_For_Bad_Folder_No_Exist(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetFileInfo("/bad folder/"); Assert.False(result.Exists, "Somehow exists."); }
public void GetDirectoryContents_Given_Sub_Folder_With_Files_Works(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetDirectoryContents("/folder with files/sub folder"); Assert.True(result.Exists, "Doesn't exists."); Assert.Single(result); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var provider = new ZipFileProvider("static.zip"); var fileInfo = provider.GetFileInfo("/favicon.ico"); Console.WriteLine(fileInfo.Name); }
public void GetDirectoryContents_Given_Top_Folder_Without_Files_Works(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetDirectoryContents("/folder without files"); Assert.True(result.Exists, "Doesn't exists."); Assert.Empty(result); }
public void GetDirectoryContents_Given_Top_Folder_With_Files_Works(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetDirectoryContents("/folder with files"); Assert.True(result.Exists, "Doesn't exists."); Assert.Equal(2, result.Count()); // both file and subfolder }
public void GetDirectoryContents_Given_Root_Exists_With_No_Files() { var provider = new ZipFileProvider(TestData.No_Data_Zip_File); var result = provider.GetDirectoryContents("/"); Assert.True(result.Exists, "Doesn't exist."); Assert.Empty(result); }
public void GetDirectoryContents_Given_Root_Exists_With_Files(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetDirectoryContents("/"); Assert.True(result.Exists, "Doesn't exist."); Assert.Equal(4, result.Count()); }
public void GetFileInfo_For_Real_File_In_SubFolder_Works(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetFileInfo("/folder with files/sub folder/sub file 2.txt"); Assert.True(result.Exists, "File 2 don't exist."); Assert.False(result.IsDirectory, "Not a file"); Assert.Equal(34, result.Length); }
public void GetFileInfo_Given_null_Or_Empty_Returns_Not_Exists() { var provider = new ZipFileProvider(TestData.No_Data_Zip_File); var result = provider.GetFileInfo(null); Assert.False(result.Exists, "Says exists."); result = provider.GetFileInfo(""); Assert.False(result.Exists, "Says exists."); }
private void SaveFileToApk(string apkFileName, string toFileName, string sourceFile) { using (var apk = new ZipFileProvider(apkFileName, FileCacheMode.None, false, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { using (var fs = File.OpenRead(sourceFile)) { apk.QueueWriteStream(toFileName, fs, true, true); apk.Save(); } } }
private bool CheckApkHasModTagFile(string apkFilename) { using (var apk = new ZipFileProvider(apkFilename, FileCacheMode.None, true, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { if (apk.FileExists(MOD_TAG_FILE)) { return(true); } } return(false); }
private void AddTagFileToApk(string apkFilename) { using (var apk = new ZipFileProvider(apkFilename, FileCacheMode.None, false, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { if (apk.FileExists(MOD_TAG_FILE)) { Log.LogMsg("APK file already had the mod's tag file."); return; } apk.Write(MOD_TAG_FILE, new byte[1], true, false); apk.Save(); } }
public void GetFileInfo_Always_Returns_Not_Exists_For_Non_Root_Paths() { var provider = new ZipFileProvider(TestData.No_Data_Zip_File); var result = provider.GetFileInfo("/file"); Assert.False(result.Exists, "Says exists."); result = provider.GetFileInfo("/folder/"); Assert.False(result.Exists, "Says exists."); result = provider.GetFileInfo("/folder/file"); Assert.False(result.Exists, "Says exists."); }
public void GetDirectoryContents_Given_Non_root_Returns_no_exists() { var provider = new ZipFileProvider(TestData.No_Data_Zip_File); var result = provider.GetDirectoryContents("/file"); Assert.False(result.Exists, "Says exists."); result = provider.GetDirectoryContents("/folder/"); Assert.False(result.Exists, "Says exists."); result = provider.GetDirectoryContents("/folder/file"); Assert.False(result.Exists, "Says exists."); }
public void GetDirectoryContents_Given_Bad_Folder_Path_Returns_no_exists(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetDirectoryContents("/file"); Assert.False(result.Exists, "Says exists."); result = provider.GetDirectoryContents("/folder/"); Assert.False(result.Exists, "Says exists."); result = provider.GetDirectoryContents("/folder/file"); Assert.False(result.Exists, "Says exists."); }
public void GetFileInfo_For_Real_File_In_Root_Works(string zipData) { var provider = new ZipFileProvider(zipData); var result = provider.GetFileInfo("/file 0.txt"); Assert.True(result.Exists, "File 0 don't exist."); Assert.False(result.IsDirectory, "Not a file"); Assert.Equal(0, result.Length); result = provider.GetFileInfo("/file 1.txt"); Assert.True(result.Exists, "File 1 don't exist."); Assert.False(result.IsDirectory, "Not a file"); Assert.Equal(17, result.Length); }
public void Watch_Always_Returns_NullChangeToken() { var provider = new ZipFileProvider(TestData.No_Data_Zip_File); // prolly a bad test case but anyway var result = provider.Watch(null); Assert.IsType <NullChangeToken>(result); result = provider.Watch(""); Assert.IsType <NullChangeToken>(result); result = provider.Watch("/"); Assert.IsType <NullChangeToken>(result); result = provider.Watch("/asdf"); Assert.IsType <NullChangeToken>(result); }
private void SignApk(string apkFilename) { try { using (var apk = new ZipFileProvider(apkFilename, FileCacheMode.None, false, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { ApkSigner signer = new ApkSigner(QuestomAssets.BeatSaber.BSConst.DebugCertificatePEM); signer.Sign(apk); } UpdateStatus("APK signed!"); } catch (Exception ex) { Log.LogErr($"Exception signing the APK {apkFilename}!", ex); UpdateStatus("Error re-signing the APK!"); throw new ModException($"Exception signing the APK {apkFilename}!", ex); } }
private void AddManifestModToApk(string apkFilename) { UpdateStatus("Modding the manifest in the APK..."); try { using (var apk = new ZipFileProvider(apkFilename, FileCacheMode.None, false, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { using (var resStream = _context.Resources.OpenRawResource(Resource.Raw.manifestmod)) { apk.QueueWriteStream("AndroidManifest.xml", resStream, true, true); apk.Save(); } } } catch (Exception ex) { Log.LogErr("Error modding the manifest in the APK", ex); UpdateStatus("Error modding the manifest in the APK!"); throw new ModException("Error modding the manifest in the APK", ex); } }
public static IProvider Get(string fileName, long skip) { IProvider provider; string extension = System.IO.Path.GetExtension (fileName).ToUpper (); switch (extension) { case ".ZIP": case ".RAR": case ".TAR": case ".GZIP": case ".GZ": case ".7Z": provider = new ZipFileProvider (fileName, skip); break; default: provider = new FileProvider (fileName, skip); break; } return provider; }
private string GetFromApkToFile(string apkFileName, string getFilename, string destinationFile = null) { string tempFile; if (destinationFile != null) { tempFile = destinationFile; } else { tempFile = Java.IO.File.CreateTempFile(getFilename, "", _context.ExternalCacheDir).AbsolutePath; } using (var apk = new ZipFileProvider(apkFileName, FileCacheMode.None, false, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { using (var fs = File.Open(tempFile, FileMode.Create, FileAccess.ReadWrite)) { using (var readStream = apk.GetReadStream(getFilename, true)) readStream.CopyTo(fs); } } return(tempFile); }
private bool CheckApkHasAllTagFiles(string apkFilename) { bool hasModTag = false; bool hasModloaderTag = false; using (var apk = new ZipFileProvider(apkFilename, FileCacheMode.None, true, QuestomAssets.Utils.FileUtils.GetTempDirectory())) { if (apk.FileExists(MOD_TAG_FILE)) { hasModTag = true; } if (apk.FileExists(MODLOADERV2_TAG_FILE)) { hasModloaderTag = true; } if (hasModTag && hasModloaderTag) { return(true); } } return(hasModTag && hasModloaderTag); }
/// <summary> /// Creates an instance of <see cref="ZipFileProvider"/> using a zip file as stream, uses it to initialize /// a <seealso cref="FileModule"/>, and adds the latter to a module container, /// giving it the specified <paramref name="name"/> if not <see langword="null"/>. /// </summary> /// <typeparam name="TContainer">The type of the module container.</typeparam> /// <param name="this">The <typeparamref name="TContainer"/> on which this method is called.</param> /// <param name="name">The name.</param> /// <param name="baseRoute">The base route of the module.</param> /// <param name="zipFileStream">The zip file as stream.</param> /// <param name="configure">A callback used to configure the module.</param> /// <returns><paramref name="this"/> with a <see cref="FileModule"/> added.</returns> /// <exception cref="NullReferenceException"><paramref name="this"/> is <see langword="null"/>.</exception> /// <seealso cref="FileModule"/> /// <seealso cref="ZipFileProvider"/> /// <seealso cref="IWebModuleContainer.Modules"/> /// <seealso cref="IComponentCollection{T}.Add"/> public static TContainer WithZipFileStream <TContainer>( this TContainer @this, string?name, string baseRoute, Stream zipFileStream, Action <FileModule>?configure = null) where TContainer : class, IWebModuleContainer { #pragma warning disable CA2000 // Call Dispose on disposable - Ownership of provider is transferred to module var provider = new ZipFileProvider(zipFileStream); #pragma warning restore CA2000 try { var module = new FileModule(baseRoute, provider); return(WithModule(@this, name, module, configure)); } catch { provider.Dispose(); throw; } }
public void Init() { //init temp folder TempDirectory = TestUtil.CreateTestDirectory(); //create copy of test ZIP file within temp folder string path = Path.Combine(TempDirectory.FullName, "TestFile.zip"); File.WriteAllBytes(path, Resources.TestFile); TestZipFile = new FileInfo(path); //init transfer stores InMemoryTransferStore <ZipDownloadTransfer> DownloadTransferStore = new InMemoryTransferStore <ZipDownloadTransfer>(); InMemoryTransferStore <ZipUploadTransfer> UploadTransferStore = new InMemoryTransferStore <ZipUploadTransfer>(); //init configuration var tempFactory = new TempFileStreamFactory(TempDirectory.FullName); var configuration = new ZipFileSystemConfiguration(TestZipFile, tempFactory); configuration.RootName = "Test Root"; configuration.DownloadStore = DownloadTransferStore; configuration.UploadStore = UploadTransferStore; configuration.DownloadTokenExpirationTime = TimeSpan.FromHours(24); configuration.UploadTokenExpirationTime = TimeSpan.FromHours(24); configuration.DefaultDownloadBlockSize = 32768; configuration.MaxDownloadBlockSize = 32768 * 2; configuration.MaxUploadBlockSize = 32768 * 4; AdjustFileSystemConfiguration(configuration); FileSystemConfiguration = configuration; //create provider Provider = new ZipFileProvider(FileSystemConfiguration); InitInternal(); }