//localfile 资源文件本地化 namespace fsys; class localfile{ ctor( path,extname ){ if( #path > 0x410/*_MAX_PATH_U8*/){ var bin = path; this._tempdir= ..io.tmpname( ..string.random(5) ); ..io.createDir(this._tempdir); this._path = ..io.joinpath( this._tempdir, ..string.concat(..string.random(5),extname) ); ..string.save(this._path,bin ); ..table.gc(this,"free"); } elseif( ..io.localpath(path) ) { if( not ..io.exist(path) ){ var bin = ..string.load(path); if( !bin ) return; var p = ..io.splitpath(path); this._tempdir= ..io.tmpname( p.name ); ..io.createDir(this._tempdir); this._path = ..io.joinpath( this._tempdir,p.file ); ..string.save(this._path,bin ); ..table.gc(this,"free"); } else { this._path = ..io.fullpath(path) } } else { this._path = path; } path = null; extname = null; }; temp = function(){ return this._tempdir; }; free = function(){ if( this._tempdir ) ..io.remove( this._tempdir ) }; path = function(){ return this._path; }; bindObject = function(obj){ _bind_objects[obj] = this; }; loadDll = function(c){ var dll = ..raw.loadDll(this.path(),,c); _bind_objects[dll] = this; return dll; }; @_meta; } namespace localfile{ _meta = { _tostring = function(){ return owner._path; } } _bind_objects = { @{_weak="k"} } } /**intellisense() fsys.localfile = 如果参数传入的不是硬盘文件路径,而是资源文件或内存数据\n则创建临时文件以获取本地路径 fsys.localfile(.("/res/->->->") = 创建资源文件路径本地化对象,\n该对象用于保证资源文件返回的是本地路径\n路径会保持原来的文件名 fsys.localfile(.(内存数据,"->默认后缀名") = 参数@1长度大于260字节,\n则使用指定的后缀名生成临时文件保存该数据 fsys.localfile() = !fsys_localfile. !fsys_localfile.path() = 本地化的完整路径 !fsys_localfile.temp() = 如果创建了临时文件则返回临时目录\n如果该函数返回值为空则path为普通路径 !fsys_localfile.free() = 删除临时文件 !fsys_localfile.loadDll(.(调用约定) = 加载 DLL !fsys_localfile.loadDll() = !dllModule. !fsys_localfile.bindObject(.(对象) = 绑定使用该文件的对象 end intellisense**/