工具箱egret读取自己的配置文件

Posted harrickheng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了工具箱egret读取自己的配置文件相关的知识,希望对你有一定的参考价值。

推荐类库:JSZip

/**
 * Created by d8q8 on 2015/5/25.
 * @class JSZip
 * @constructor
 **/
interface JSZip 
    file(path:string): JSZipObject;
    file(path:RegExp): JSZipObject[];
    file(path:string, data:any, options?:JSZipFileOptions): JSZip;
    folder(name:string): JSZip;
    folder(name:RegExp): JSZipObject[];
    filter(predicate:(relativePath:string, file:JSZipObject) => boolean): JSZipObject[];
    remove(path:string): JSZip;
    generate(options?:JSZipGeneratorOptions): any;
    load(data:any, options:JSZipLoadOptions): JSZip;


interface JSZipObject 
    name: string;
    dir: boolean;
    date: Date;
    comment: string;
    options: JSZipObjectOptions;

    asText(): string;
    asBinary(): string;
    asArrayBuffer(): ArrayBuffer;
    asUint8Array(): Uint8Array;
    asNodeBuffer(): Buffer;


interface JSZipFileOptions extends JSZipObjectOptions 
    compressionOptions?:Object;
    comment?: string;
    optimizedBinaryString?: boolean;
    createFolders?: boolean;
    unixPermissions?:number;
    dosPermissions?:number;


interface JSZipObjectOptions 
    base64?: boolean;
    binary?: boolean;
    dir?: boolean;
    date?: Date;
    compression?: string;


interface JSZipGeneratorOptions 
    base64?: boolean;
    compression?: string;
    compressionOptions?:Object;
    type?: string;
    comment?: string;
    mimeType?:string;
    platform?:string;


interface JSZipLoadOptions 
    base64?: boolean;
    checkCRC32?: boolean;
    optimizedBinaryString?: boolean;
    createFolders?: boolean;


interface JSZipSupport 
    arraybuffer: boolean;
    uint8array: boolean;
    blob: boolean;
    nodebuffer: boolean;


interface Buffer 
    data?:any;
    encoding?:string;


interface DEFLATE 
    compress(input:string, compressionOptions:level:number): Uint8Array;
    compress(input:number[], compressionOptions:level:number): Uint8Array;
    compress(input:Uint8Array, compressionOptions:level:number): Uint8Array;

    uncompress(input:string): Uint8Array;
    uncompress(input:number[]): Uint8Array;
    uncompress(input:Uint8Array): Uint8Array;


declare var JSZip:
    (): JSZip;
    (data:any, options?:JSZipLoadOptions): JSZip;
    new (): JSZip;
    new (data:any, options?:JSZipLoadOptions): JSZip;

    prototype: JSZip;
    support: JSZipSupport;
    compressions: 
        DEFLATE: DEFLATE;
    


declare module "jszip" 
    export = JSZip;


interface FileSaver 
    (data:Blob, filename:string): void


declare var saveAs:FileSaver;

StdConfig

class StdConfig 
    public constructor() 

    
    private static _zip: JSZip;//配置压缩包缓存
    private static _cfgls: Object = new Object();

        public static parseCfg(cfg: string): string     
        return StdConfig._zip.file(cfg).asText();    
            

        public static async parseStd(byte: egret.ByteArray) 
        StdConfig._hasInit = true;
        StdConfig._zip = new JSZip(byte.buffer);
                
                StdConfig.parseFirstPayConfig("fristpayrebate");
                //... ...
            

        private static _getFirstPayById: (id) => StdFirstPay;
        private static parseFirstPayConfig(cfg: string) 
          cfg = StdConfig.parseCfg(cfg);
          let payAward: any = JSON.parse(cfg);
          StdConfig._getFirstPayById = function (id): StdFirstPay 
              if (!payAward) 
                  throw new Error("缺少首充奖励配置");
              
              return payAward[id - 1];
        
                        

 

以上是关于工具箱egret读取自己的配置文件的主要内容,如果未能解决你的问题,请参考以下文章

Egret之egretProperties.json(EUI)

如何在ts中调用js文件

bash配置文件

读取配置文件工具demo

Egret 压缩与解压(jszip)

中兴机顶盒现场配置工具读取配置信息获取所有ini配置文件失败