/** * initialize the script manager. */ public override void init(ServletConfig config) { _config = config; _servletContext = config.getServletContext(); checkServletAPIVersion(); string pwd = new FilePath(_servletContext.getRealPath("/")); string webInfDir = new FilePath(_servletContext.getRealPath("/WEB-INF")); getQuercus().setPwd(pwd); getQuercus().setWebInfDir(webInfDir); // need to set these for non-Resin containers if (!CurrentTime.isTest() && !getQuercus().isResin()) { Vfs.setPwd(pwd); WorkDir.setLocalWorkDir(webInfDir.lookup("work")); } initImpl(config); getQuercus().init(); getQuercus().start(); }
/** * Parses the AFM file. * If the webInfLibPath @is not null or empty and @is the valid absolute path to this * applications WEB-INF/lib folder (or any other folder containing jars to load), * jars inside that folder are also searched for fonts. */ public Font parse(String webInfLibPath, string name) { MergePath mergePath = new MergePath(); mergePath.addClassPath(); File webInfLibFile = new File(webInfLibPath); if (webInfLibPath != null && !webInfLibPath.isEmpty() && webInfLibFile.isDirectory()) { string webInfPath = Vfs.lookup(webInfLibFile.getAbsolutePath()); for (File f : webInfLibFile.listFiles()) { /* * only look for files that are either jars or zips */ if (f.isFile() && (f.getAbsolutePath().endsWith(".jar") || f.getAbsolutePath().endsWith(".zip"))) { /* * get a path object with the Jar relative to WEB-INF/lib */ string jarPath = webInfPath.lookup(f.getName()); /* * Encapsulate it as a JarPath, else mergePath.lookup does not look * "into" the jar when looking for resources */ mergePath.addMergePath(JarPath.create(jarPath)); } } } string path = mergePath.lookup("com/caucho/quercus/lib/pdf/font/" + name + ".afm"); if (!path.canRead()) { if ("".equals(name)) { throw new IllegalArgumentException(L.l("Missing font name")); } throw new FileNotFoundException(L.l("Can't find font '{0}'", name)); } _is = path.openRead(); try { return(parseTop()); } finally { _is.close(); } }
protected override void handleThrowable(HttpServletResponse response, Throwable e) { log.log(Level.WARNING, e.ToString(), e); OutputStream os = response.getOutputStream(); WriteStream @out = Vfs.openWrite(os); @out.println(e); @out.close(); }
/** * Printable flat report */ public void printHotSpotReport(OutputStream os) { WriteStream @out = Vfs.openWrite(os); ArrayList <ProfileMethod> methodList = new ArrayList <ProfileMethod>(_methodMap.values()); Collections.sort(methodList, new SelfMicrosComparator()); double totalMicros = 0; int maxNameLength = 0; for (ProfileMethod method : methodList) { int len = method.getName().length(); if (maxNameLength < len) { maxNameLength = len; } totalMicros += method.getSelfMicros(); } @out.println(); @out.println("Hot Spot Profile: " + _url + " at " + new Date(_timestamp)); @out.println(); @out.println(" self(us) total(us) count %time %sum name"); @out.println("----------------------------------------------------"); double sumMicros = 0; for (ProfileMethod method : methodList) { string name = method.getName(); long selfMicros = method.getSelfMicros(); sumMicros += selfMicros; @out.print(String.format("%7dus", selfMicros)); @out.print(String.format(" %8dus", method.getTotalMicros())); @out.print(String.format(" %6d", method.getCount())); @out.print(String.format(" %6.2f%%", 100.0 * selfMicros / totalMicros)); @out.print(String.format(" %6.2f%%", 100.0 * sumMicros / totalMicros)); @out.print(" " + name); @out.println(); } @out.println(); @out.close(); }
public static bool Repack(string realPath, string alt, bool randomize = false, int lz4blockSize = 128 * 1024) { if (!File.Exists(alt)) { using (var f = File.OpenRead(realPath)) { using (var fo = File.Create(alt)) { return(Vfs.Repack(f, fo, randomize, lz4blockSize)); } } } return(true); }
public static List <string> GetAssetBundleNameListFromPath(string path, bool subdirCheck = false) { return(Vfs.GetAssetBundleNameListFromPath(path, subdirCheck)); #if false List <string> result = new List <string>(); string basePath = AssetBundleManager.BaseDownloadingURL; string path2 = basePath + path; if (!Directory.Exists(path2)) { return(result); } string[] source = (!subdirCheck) ? Directory.GetFiles(path2, "*.unity3d") : Directory.GetFiles(path2, "*.unity3d", SearchOption.AllDirectories); return((from s in source select s.Replace(basePath, string.Empty)).ToList()); #endif }
public bool CopyABdata() { var target = Dir.mod + "abdata/"; if (!settings.withoutManifest && Directory.Exists(target)) { return(false); } bool res = false; foreach (var sfn in Directory.GetFiles(Dir.abdata, "*.unity3d", SearchOption.AllDirectories)) { var fn = sfn.Replace("\\", "/").Substring(Dir.abdata.Length); if (LoadedAssetBundle.cache.TryGetValue(fn, out LoadedAssetBundle ab)) { if (ab.hasRealManifest) { continue; } if (ab.name.StartsWith("sound/")) { continue; } } var fout = target + fn; if (File.Exists(fout)) { continue; } Directory.CreateDirectory(target + fn.Remove(fn.LastIndexOf('/'))); var fin = Dir.abdata + fn; if (Vfs.Repack(fin, fout, true)) { res = true; print($"Moved {fn}"); } else { print($"Failed to move {fn}"); File.Delete(fout); } } return(res); }
public static void PostInit() { isInitialized = true; fsGlobalConfig.SerializeDefaultValues = false; JSON.Init(); earlydone = true; if (!initConfig) { InitConfig(); // If we're running standalone ConfigDialog(); } Vfs.CheckInit(); initdone = true; settings.Apply(true); settings.UpdateCamera(null); SaveConfig(); form?.BringToFront(); }
public override void Awake() { if (!settings.loadMods) { return; } var needRescan = false; needRescan |= CanonizeZip(); needRescan |= CanonizeCsv(); needRescan |= CopyABdata(); if (needRescan) { print("VFS changed; rescanning"); LoadedAssetBundle.GCBundles(); Vfs.Rescan(true); Vfs.Save(); } }
public AssetBundle TryLoadAB(string path) { Debug.Log("trying to load ", path); var ab = AssetBundle.LoadFromFile(Dir.root + path); if (ab != null) { return(ab); } var key = Ext.HashToString(path.ToBytes()).Substring(0, 12); var alt = Dir.cache + key + ".unity3d"; Vfs.Repack(realPath, alt, true); Debug.Log("no dice, trying alternat path at ", alt); var ret = AssetBundle.LoadFromFile(alt); if (ret == null) { Debug.Error("Bundle load (try 1) failed ", path); } return(ret); }
public DriveItemSource() { Vfs.Initialize(); monitor = Gnome.Vfs.VolumeMonitor.Get(); items = new List <Item> (); }
public object LoadVirtualAsset(string name, Type t) { if (!virtualAssets.TryGetValue(name.ToLower(), out string virt)) { return(null); } Debug.Log("Trying to load virtual asset from ", this.name, name, virt); var path = Dir.root + virt; if (virt.EndsWith(".png") || virt.EndsWith(".jpg")) { var tex = new Texture2D(2, 2); tex.LoadImage(File.ReadAllBytes(path)); if (virt.Contains("clamp")) { tex.wrapMode = TextureWrapMode.Clamp; } if (virt.Contains("repeat")) { tex.wrapMode = TextureWrapMode.Repeat; } tex.name = name; return(tex); } if (typeof(IDumpable).IsAssignableFrom(t)) { IDumpable obj; if (typeof(ScriptableObject).IsAssignableFrom(t)) { obj = ScriptableObject.CreateInstance(t) as IDumpable; } else { obj = Activator.CreateInstance(t) as IDumpable; } if (obj.Unmarshal(Encoding.UTF8.GetString(File.ReadAllBytes(path)).StripBOM(), Vfs.GetExt(virt), name, virt)) { if (obj is UnityEngine.Object) { (obj as UnityEngine.Object).name = name; } return(obj); } } if (typeof(TextAsset).IsAssignableFrom(t) && (virt.EndsWith(".txt") || virt.EndsWith(".lst"))) { var txt = ScriptableObject.CreateInstance <TextAsset>(); txt.name = name; txt.path = virt; txt.bytes = File.ReadAllBytes(path); return(txt); } Debug.Log("No virtual asset loaded"); return(null); }
public bool CanonizeZip() { var target = Dir.mod; print("Unzipping mods into " + Path.GetFullPath(target)); var zipdir = Dir.root + "mods"; bool needRescan = false; LoadedAssetBundle.GCBundles(); foreach (var zipfn in Directory.GetFiles(zipdir, "*.zip", SearchOption.AllDirectories)) { var modname = Path.GetFileNameWithoutExtension(zipfn); //print("@ " + modname); if (Directory.Exists(target + modname)) { continue; } needRescan = true; print("Extracting " + Path.GetFileName(zipfn)); using (var fs = File.Open(zipfn, FileMode.Open, FileAccess.Read, FileShare.Read)) { var zip = new ZipFile(fs); var guid = modname; // pick guid from manifest if its there var manifest = zip.GetEntry("manifest.xml"); if (manifest != null) { XmlDocument doc = new XmlDocument(); doc.LoadXml(Encoding.UTF8.GetString(entry2bytes(zip, manifest)).StripBOM()); guid = doc.SelectSingleNode("//guid").InnerText; } foreach (ZipEntry entry in zip) { if (!entry.IsFile) { continue; } var efn = entry.Name; if (efn.ToLower().EndsWith("manifest.xml")) { continue; } if (efn.StartsWith("abdata/")) { efn = efn.Substring(7); } var prefix = "list/characustom/"; var basename = Path.GetFileNameWithoutExtension(efn); var bytes = entry2bytes(zip, entry); // make the cat manifest csv canonical if (efn.StartsWith(prefix) && efn.EndsWith(".csv")) { var str = Encoding.UTF8.GetString(bytes); var ex = ScriptableObject.CreateInstance <ExcelData>().Import(CSV.ParseCSV(str)); var firstrow = ex.list.First().list; var cat = -1; var dist = 0; if (firstrow.Count == 1) { try { cat = int.Parse(ex[0, 0].Trim()); dist = int.Parse(ex[1, 0].Trim()); ex.list.RemoveRange(0, 3); } catch (System.Exception exc) { print(exc.Message); print(ex[0, 0]); print(ex[1, 0]); }; } else { try { cat = int.Parse(basename.Split('_')[0]); } catch { }; } // if we can't figure out the category, bail on this csv if (cat == -1) { print(zipfn + " unzip failed"); continue; } efn = $"{prefix}{dist:D2}_{guid}/{cat}_{basename}.csv"; bytes = ex.Marshal().AddBOM().ToBytes(); } // if it is a hardmod, check that the contents of the bundle fully match the file overriden. var hardab = Dir.abdata + efn; var oldefn = efn; int nmissing = 0; efn = target + modname + "/" + efn; Directory.CreateDirectory(Path.GetDirectoryName(efn)); bool nukecab = true; if (efn.EndsWith(".unity3d") && File.Exists(hardab)) { // if it overwrites in its entirety, do not nuke the cab as deps amy point to it nukecab = false; var ab = AssetBundle.LoadFromMemory(bytes); if (ab == null) { print($"WARNING: {efn} failed to load, skipping."); continue; } var abnames = new HashSet <string>(ab.GetAllAssetNames().Select((x) => Path.GetFileNameWithoutExtension(x)).ToList()); ab.Unload(true); var origab = AssetBundle.LoadFromFile(hardab); if (origab == null) { goto skip2; } // Now load the original and check the replacement has all its assets foreach (var ass in origab.GetAllAssetNames()) { var shass = Path.GetFileNameWithoutExtension(ass); if (!abnames.Contains(shass)) { //print($"WARNING: {Path.GetFileName(efn)}: {shass} is missing {oldefn}"); nmissing++; } } origab.Unload(true); // missing assets; nuke cab if (nmissing > 0) { nukecab = true; } } skip2: //print(".. Extracted " + efn); if (nmissing != 0) { efn = Directory.GetParent(efn).FullName + "/+" + Path.GetFileName(efn); } if (efn.EndsWith(".unity3d")) { using (var fo = File.Create(efn)) if (Vfs.Repack(new MemoryStream(bytes), fo, nukecab | sideloader_compat)) { bytes = null; } } if (bytes != null) { File.WriteAllBytes(efn, bytes); } } } } print("Done"); return(needRescan); }
/** * Printable hierarchy report */ public void printHierarchyReport(OutputStream os) { WriteStream @out = Vfs.openWrite(os); ArrayList <ProfileMethod> methodList = new ArrayList <ProfileMethod>(_methodMap.values()); Collections.sort(methodList, new TotalMicrosComparator()); double totalMicros = methodList.get(0).getTotalMicros(); int maxNameLength = 0; @out.println(); @out.println("Hierarchy: " + _url + " at " + new Date(_timestamp)); @out.println(); @out.println(" total(us) self(us) count %time %sum name"); @out.println("----------------------------------------------------"); double sumMicros = 0; for (ProfileMethod method : methodList) { string name = method.getName(); long ownTotalMicros = method.getTotalMicros(); long selfMicros = method.getSelfMicros(); sumMicros += selfMicros; @out.println(); ArrayList <ProfileItem> parentList = new ArrayList <ProfileItem>(method.getParentItems()); Collections.sort(parentList, new ItemMicrosComparator()); for (ProfileItem item : parentList) { @out.print(" "); @out.print(String.format(" %7dus", item.getMicros())); @out.print(String.format(" %6d", item.getCount())); @out.print(String.format(" %-19s", item.getParent())); @out.print(String.format("%6.2f%%", 100.0 * item.getMicros() / ownTotalMicros)); @out.println(); } @out.print(String.format(" %6.2f%%", 100.0 * ownTotalMicros / totalMicros)); @out.print(String.format(" %7dus", method.getTotalMicros())); @out.print(String.format(" %6d", method.getCount())); @out.print(String.format(" %-22s", name)); @out.print(String.format("%6.2f%%", 100.0 * selfMicros / ownTotalMicros)); @out.print(String.format(" %7dus", method.getSelfMicros())); @out.println(); ArrayList <ProfileItem> childList = new ArrayList <ProfileItem>(method.getChildItems()); Collections.sort(childList, new ItemMicrosComparator()); for (ProfileItem item : childList) { @out.print(" "); @out.print(String.format(" %7dus", item.getMicros())); @out.print(String.format(" %6d", item.getCount())); @out.print(String.format(" %-19s", item.getName())); @out.print(String.format("%6.2f%%", 100.0 * item.getMicros() / ownTotalMicros)); @out.println(); } } @out.println(); @out.close(); }
public static void CheckInit() { Vfs.CheckInit(); }
public StdHandle sceKernelStdoutReopen(string File, HleIoFlags Flags, Vfs.SceMode Mode) { StdOut = (StdHandle)IoFileMgrForUser.sceIoOpen(File, Flags, Mode); //Console.WriteLine("StdOut: {0}", StdOut); return StdOut; }
public StdHandle sceKernelStderrReopen(string File, HleIoFlags Flags, Vfs.SceMode Mode) { StdError = (StdHandle)IoFileMgrForUser.sceIoOpen(File, Flags, Mode); return StdError; }
static MyTextView() { Vfs.Initialize(); }
static MimeTypeHelper() { Vfs.Initialize(); }