Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1022668 // resourceLoaderFromJar

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (6664L/45K).

1  
static IResourceLoader resourceLoaderFromJar(File mainJar, File unpackDir) {
2  
  print("Unpacking to: " + unpackDir);
3  
  
4  
  SS titles = cast safeUnstructure(loadTextFileFromZip(mainJar, "snippet-titles.struct"));
5  
  assertNempty("Snippet titles", titles);
6  
  Map<S, Int> types = cast safeUnstructure(loadTextFileFromZip(mainJar, "snippet-types.struct"));
7  
8  
  ret new IResourceLoader {
9  
    public S loadSnippet(S snippetID) {
10  
      ret loadTextFileFromZip(mainJar, psI(snippetID) + ".text");
11  
    }
12  
    
13  
    public S getTranspiled(S snippetID) {
14  
      S src = loadTextFileFromZip(mainJar, psI(snippetID) + ".transpiled");
15  
      if (empty(src))
16  
        print("Warning: Transpilation for " + snippetID + " not found");
17  
      ret src;
18  
    }
19  
    
20  
    public int getSnippetType(S snippetID) {
21  
      ret or0(types.get(fsI(snippetID)));
22  
    }
23  
    
24  
    public S getSnippetTitle(S snippetID) {
25  
      ret titles.get(fsI(snippetID));
26  
    }
27  
    
28  
    public File loadLibrary(S snippetID) {
29  
      long id = psI(snippetID);
30  
      if (isImageServerSnippet(id)) 
31  
        ret optExtractFileFromZipToDir_tryMultipleNames(mainJar, unpackDir, id + ".png", id + ".gif");
32  
      else
33  
        ret optExtractFileFromZipToDir(mainJar, unpackDir, id + ".bin");
34  
    }
35  
    
36  
    public File pathToJavaXJar() {
37  
      ret mainJar;
38  
    }
39  
  };
40  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1022668
Snippet name: resourceLoaderFromJar
Eternal ID of this version: #1022668/6
Text MD5: a5b9a50cf43ac2ccc31f58f2a4d2d546
Transpilation MD5: aa5a5d0ed4b82e95749fd7705be6777b
Author: stefan
Category: javax / packaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-14 13:46:01
Source code size: 1341 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 379 / 480
Version history: 5 change(s)
Referenced in: [show references]