IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.CoreLib.Modules.Resources Class Reference

Static Public Member Functions

static string ToPackageName (string name)
 Derive a package name for a resource. The package name returned by this method may not be a legal package name. This method returns null if the resource name ends with a "/" (a directory) or the resource name does not contain a "/".
 
static string ToResourceName (string dir, string file)
 Returns a resource name corresponding to the relative file path between dir and file . If the file is a directory then the name will end with a "/", except the top-level directory where the empty string is returned.
 
static ? string ToFilePath (string dir, string name)
 Returns a file path to a resource in a file tree. If the resource name has a trailing "/" then the file path will locate a directory. Returns null if the resource does not map to a file in the tree file.
 

Detailed Description

Definition at line 7 of file Resources.cs.

Member Function Documentation

◆ ToFilePath()

static ? string IKVM.CoreLib.Modules.Resources.ToFilePath ( string dir,
string name )
static

Returns a file path to a resource in a file tree. If the resource name has a trailing "/" then the file path will locate a directory. Returns null if the resource does not map to a file in the tree file.

Returns

Definition at line 62 of file Resources.cs.

63 {
64 var expectDirectory = name.EndsWith('/');
65 if (expectDirectory)
66 name = name.TrimEnd('/');
67
68 var path = ToSafeFilePath(name);
69 if (path is not null)
70 {
71 var file = Path.Combine(dir, path);
72 if (Directory.Exists(file) || (Directory.Exists(file) == false && expectDirectory == false))
73 return file;
74 }
75
76 return null;
77 }

◆ ToPackageName()

static string IKVM.CoreLib.Modules.Resources.ToPackageName ( string name)
static

Derive a package name for a resource. The package name returned by this method may not be a legal package name. This method returns null if the resource name ends with a "/" (a directory) or the resource name does not contain a "/".

Definition at line 15 of file Resources.cs.

16 {
17 int index = name.LastIndexOf('/');
18 if (index == -1 || index == name.Length - 1)
19 {
20 return "";
21 }
22 else
23 {
24 return name.Substring(0, index).Replace('/', '.');
25 }
26 }

◆ ToResourceName()

static string IKVM.CoreLib.Modules.Resources.ToResourceName ( string dir,
string file )
static

Returns a resource name corresponding to the relative file path between dir and file . If the file is a directory then the name will end with a "/", except the top-level directory where the empty string is returned.

Definition at line 33 of file Resources.cs.

34 {
35 // full dir path, with ending separator
36 dir = Path.GetFullPath(dir);
37 if (dir.EndsWith(Path.DirectorySeparatorChar) == false)
38 dir += Path.DirectorySeparatorChar;
39
40 // normalize relative path off of dir
41 file = Path.Combine(dir, file);
42 if (file.StartsWith(dir) == false)
43 throw new InvalidOperationException("Resource file does not exist in directory.");
44
45 // cut directory off of file path
46 file = file[dir.Length..];
47 if (Path.DirectorySeparatorChar != '/')
48 file = file.Replace(Path.DirectorySeparatorChar, '/');
49
50 // ensure directory path ends with separator
51 if (file != "" && Directory.Exists(file))
52 file += "/";
53
54 return file;
55 }

The documentation for this class was generated from the following file: