Exemplo n.º 1
0
    def ScanAudioFile(self, dir, filejson):
        if not os.path.exists(dir):
            return
        listFile = []

        dirsave = FileUtil.GetLastDirofDir(filejson)
        FileUtil.CreateDir((dirsave))

        FileUtil.GetFileList(dir, "mp3", listFile)
        FileUtil.GetFileList(dir, "wav", listFile)
        FileUtil.GetFileList(dir, "ogg", listFile)

        dataRoot = json.loads("{}")
        #        "BtnIconPlay" : {
        #     "path" : "App/UI/Common/Button/BtnIconPlay.png"
        # },
        for fileimage in listFile:
            filepath = fileimage.replace(
                mainResource.GetRootUnityAssets() + "/", "")
            filepath = filepath.replace(self.dirCloudResHead, "")
            # item= json.loads("{}")
            # item["path"]=filepath
            name = FileUtil.GetPathNameWithoutExt(fileimage)
            dataRoot[name] = filepath

        json_str = json.dumps(dataRoot,
                              ensure_ascii=False,
                              indent=4,
                              sort_keys=True)
        FileUtil.SaveString2File(json_str, filejson)
Exemplo n.º 2
0
    def ScanImageFile(self, dir, filejson):
        # if not os.path.exists(dir):
        #     return

        listFile = []
        if os.path.exists(dir):
            FileUtil.GetFileList(dir, "png", listFile)
            FileUtil.GetFileList(dir, "jpg", listFile)
            print("listFile len=" + str(len(listFile)))
        dataRootOld = None
        if os.path.exists(filejson) == True:
            print("filejson = " + filejson)
            strfile = FileUtil.GetFileString(filejson)
            # print("strfile = "+strfile)
            dataRootOld = json.loads(strfile)
            if dataRootOld is None:
                print("dataRootOld is  none")
                print("strfile = " + strfile)
            # remove
            os.remove(filejson)

        dataRoot = json.loads("{}")
        #        "BtnIconPlay" : {
        #     "path" : "App/UI/Common/Button/BtnIconPlay.png"
        # },
        for fileimage in listFile:

            item = json.loads("{}")
            filepath = fileimage.replace(
                mainResource.GetRootUnityAssets() + "/", "")
            filepath = filepath.replace(self.dirCloudResHead, "")

            item["path"] = filepath
            name = FileUtil.GetPathNameWithoutExt(fileimage)

            # 从原来的json中恢复board
            if dataRootOld is not None:
                # print("dataRootOld is not none")
                if name in dataRootOld:
                    # print("dataRootOld  name="+name)
                    dataitem = dataRootOld[name]
                    key = "board"
                    # key = "path"
                    # if name =="BtnCommon":
                    #     # key = "board"
                    #     print("dataitem[key] = "+dataitem[key]+" name="+name)

                    if key in dataitem:
                        print("key = " + key + " name=" + name)
                        item[key] = dataitem[key]

            dataRoot[name] = item

        json_str = json.dumps(dataRoot,
                              ensure_ascii=False,
                              indent=4,
                              sort_keys=True)
        FileUtil.SaveString2File(json_str, filejson)