FileAccessPlugin
Provides standardized methods for accessing both local file and url resources. Automatically handles searching local folders for assets.
Date uploaded | 8 months ago |
Version | 1.7.2 |
Download link | LordAshes-FileAccessPlugin-1.7.2.zip |
Downloads | 5082 |
Dependency string | LordAshes-FileAccessPlugin-1.7.2 |
This mod requires the following mods to function
bbepisTaleSpire-BepInExPack
Unified BepInEx all-in-one modding pack - plugin framework, detour library
Preferred version: 5.4.10README
File Access Plugin
This unofficial TaleSpire plugin for providing a standardized method of accessing both local and internet resources (files). Plugins that use this plugin for file access will be able to access both local file resources and internet resources, without having to have different code, just by specifying a local or internet source. When using local files this plugin automatically searches plugin folders and the common folder (if present) for content which means the parent plugin does not need to worry about such details.
Change Log
1.7.2: Fixed bug with sort order
1.7.1: Hide File Not Found exception for URL based Exist unless diagnostics are on
1.7.0: Added ability to re-load the cache (needed by plugins that modify files)
1.6.0: Added Plugin namespace with related methods
1.5.3: Update to keyboard detection code
1.5.1: Improved diagnostics
1.5.1: Fixed bug with Find when using URL
1.4.1: Fix Talespire takedown bug
1.4.0: Added support for Assets folders used by CALP
1.3.1: Bug Fix: CacheSetting produces Null Exception Error
1.3.0: The SetCacheType method is marked as obsolete and does not do anything.
The cache setting is now controlled at the File Access Plugin level via
R2ModMan configuration setting. This prevents plugins from changing the
cache setting on each other.
1.3.0: Removed unnecessary log entries
1.2.3: Catalog returns bare info by default (usable in code) with option to return
extended infromation for logging purpose
1.2.1: Find returns full path if a full path source is provided
1.2.0: Supports direct path option
1.1.1: Better location of the plugins folder in case manual install was done.
1.1.0: Fixed issue with forced R2ModMan profile. Plugin now auto detects profile.
1.0.0: Initial release
Install
Install using R2ModMan or similar and reference the plugin DLL when building the parent plugin. This gives access to the LordAshes.FileAccessPlugin namespace with most of the file related functions under the sub-namespace File, some image loading function under the sub-namepace Image and an assetBundle loader under the sub-namespace of AssetBundle.
Usage
GetProtocol(string source)
Gets the protocol portion of the source. Empty string if the source is a local file or the protocol poriton (e.g. http or https) if it is a URL.
The following sub-namespaces are available...
File
AppendAllText(string source, string content)
string ReadAllText(string source)
WriteAllText(string source, string content)
Functions for appending, reading and writing the contents of the source as a single string. Note: When using a URL for the source, append and write functions perform an upload.
AppendAllLines(string source, string[] content)
string[] ReadAllLines(string source)
WriteAllLines(string source, string[] content)
Functions for appending, reading and writing the contents of the source as an string array of lines. Each line is the source is an individual entry in the array. Note: When using a URL for the source, append and write functions perform an upload.
byte[] ReadAllBytes(string source)
WriteAllBytes(string source, byte[] content)
Functions for reading and writing the contents of the source as an byte array. Note: When using a URL for the source, append and write functions perform an upload.
bool Exists(source)
Determines if the source exists. For local files it must exists in the plugin directories or the common folder. For URL the resource needs to exists at the give source.
string[] Find(source)
When the source is a local file, finds where the source is located. Returns a string array of resources that match the given source using a "contains" concept. When using any of the append, reaad or write functions from this plugin, it is not necessary to use Find because the functions take care of that on their own. However, if using a different function to access the file, the Find function can be used to obtain the complete file path and namepace of the file.
string[] Catalog(Bool extendedData)
Returns a sorted list of all available assets sorted by type and then plugin. Setting the extendedData to true (false if omitted) will provide additional information with each entry.
Image
Texture2D LoadTexture(string source)
Returns a texture loaded with the contents of the source
Sprite LoadSprite(string source)
Returns a sprite loaded with the contents of the source. Typically used for icons.
AssetBundle
AssetBundle Load(string source)
Returns an assetBundle loaded from the specified source
Plugin
string WhoAmI()
Returns the complete location and filename of the plugin that called this function.
string Location()
Returns the complete location without filename of the plugin that called this function.
Dictionary<string,object> Manifest()
Returns the calling plugin manifest if the manifest.json
file is present.
Cache
void ReloadCache()
Reload the cache with the current folders and files. This method is needed by Plugin that change the folder or file structure. If a plugin adds, deletes, or renames folders or files, it needs to call this method to have File Access Plugin update its cache.
Local File Search
When using local files, the source can specify a resource name or a folder and resource name and the plugin will automatically search the plugin folders for the specified resource. This allows the parent plugins to specify resources by name without having to concern themselves with figuring out which plugin contains the resource. If the installaton has the TaleSpire_CustomData folder in the main TaleSpire game folder then this folder is also used to locate assets.
This means that local access (append, read and write) is limited to writing in the plugin folders and the common folder (if it exists).
This also means that append and write functions only work with existing files. Thus the write functions cannot be used to make a new file but can be used to rewrite an existing file.
Full Path
Full path sources are recognized by having a colon as a second characters since such sources start with a drive letter and then are followed by a colon and the path and file name. When such sources are provided, they are used as is without looking them up in the files list or on the internet.
Cache Type
The Cache Type is now set for all plugins at the File Access Plugin level to avoid plugins from switching the cache type on each other. To change the cache type, edit the R2ModMan configuration for the File Access Plugin and choose on of the following option:
NoCacheCustomData = Only files in the CustomData sub-folders are collected. Contents are re-generated each time they are needed (allows adding contents on the fly). NoCacheCustomData = Only files in the CustomData sub-folders are collected. Contents are re-generated each time they are needed (allows adding contents on the fly). NoCacheFullListing = All files in plugin folders are added. Contents are re-generated each time they are needed (allows adding contents on the fly). CacheCustomData = Only files in the CustomData sub-folders are collected. Contents are generated once at startup (does not allow adding contents on the fly). CacheFullListing = All files in plugin folders are added. Contents are generated once at startup (does not allow adding contents on the fly).