Esempio n. 1
0
        static string saveResourceToPath <DstType, SrcType>(string baseDir,
                                                            SrcType srcObj, int objIndex, ResId objId, int objCount,
                                                            IndexedObjectConverter <SrcType, DstType> converter,
                                                            System.Func <DstType, string> nameFunc,
                                                            string baseName, bool showGui,
                                                            System.Action <DstType> dstProcessor) where DstType : IFastJsonValue
        {
            if (showGui)
            {
                ExportUtility.showProgressBar(
                    string.Format("Saving file #{0} of resource type {1}", objIndex + 1, baseName),
                    "Writing json data", objIndex, objCount);
            }
            var    dstObj = converter(srcObj, objIndex, objId);
            string fileName;

            if (dstProcessor != null)
            {
                dstProcessor(dstObj);
            }
            if (nameFunc != null)
            {
                fileName = makeJsonResourcePath(baseName, nameFunc(dstObj), objIndex);
            }
            else
            {
                fileName = makeJsonResourcePath(baseName, objIndex);
            }
            var fullPath = System.IO.Path.Combine(baseDir, fileName);

            dstObj.saveToJsonFile(fullPath);
            return(fileName);
        }
        static bool saveResourcesToPath <DstType, SrcType, StorageType>(
            List <string> outObjectPaths,
            string baseDir,
            ResourceStorageWatcher <StorageType, SrcType> objects,
            IndexedObjectConverter <SrcType, DstType> converter,
            System.Func <DstType, string> nameFunc, string baseName, bool showGui,
            System.Action <DstType> dstProcessor = null)
            where DstType : IFastJsonValue
        {
            if (converter == null)
            {
                throw new System.ArgumentNullException("converter");
            }

            bool result = false;

            try{
                if (objects != null)
                {
                    foreach (var curData in objects.getNewObjectsData())
                    {
                        //lq begin
                        var temp = saveResourceToPath(
                            baseDir, curData.data, curData.index, curData.id,
                            objects.numObjects,
                            converter, nameFunc, baseName, showGui,
                            dstProcessor
                            );

                        if (string.IsNullOrEmpty(temp) == false)
                        {
                            outObjectPaths.Add(temp);
                            result = true;
                        }
                        //end
                    }
                    objects.updateNumObjects();                    //yup. I forgot that part.
                }
                return(result);
            }
            finally{
                if (showGui)
                {
                    ExportUtility.hideProgressBar();
                }
            }
        }