Example #1
0
        public static string[] ListAllCsvFilesInCsvFolder()
        {
            string folder = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSpreadSheetFileDirectory);

            // verify csv folder
            if (!Directory.Exists(folder))
            {
                string errorStr = string.Format("CSV file folder path {} is not existed, please check CSV Folder path is vaild", folder);
                Debug.LogError(errorStr);
                throw new Exception(errorStr);
            }

            List <string> csvFiles = new List <string>();

            SearchCsvFiles(folder, ref csvFiles);

            // check duplicate file name
            for (int i = 0; i < csvFiles.Count; i++)
            {
                for (int j = i + 1; j < csvFiles.Count; j++)
                {
                    if (GetCsvDataClassName(csvFiles[i]).ToLower() == GetCsvDataClassName(csvFiles[j]).ToLower())
                    {
                        string errorStr = string.Format("There are duplicate file names in CSV file folder {0} AND {1}", csvFiles[i], csvFiles[j]);
                        throw new Exception(errorStr);
                    }
                }
            }
            return(csvFiles.ToArray());
        }
Example #2
0
        public static string[] GetAllExpiredCsvFile()
        {
            List <string> expiredCsvFiles = new List <string>();

            foreach (string csvFile in ListAllCsvFilesInCsvFolder())
            {
                string csvCodeFileName = JumpCsvEditorHelper.PathCombine(JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSourceCodeFileDirectory), JumpCsvEditorHelper.GetCsvDataClassName(csvFile) + ".cs");
                //string csvDataFileName = JumpCsvEditorHelper.PathCombine(JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory) , JumpCsvEditorHelper.GetCsvDataBinaryFileName(csvFile));
                if (!File.Exists(csvCodeFileName))
                {
                    expiredCsvFiles.Add(csvFile);
                }
                else   // check content is latest
                {
                    string className   = JumpCsvEditorHelper.GetCsvDataClassName(csvFile);
                    Type   csvCodeType = CsvHelper.GetType("JumpCSV." + className);
                    int    hashCode    = (int)(csvCodeType.GetField("mHashCode").GetValue(null));

                    string         resourcePath = JumpCsvEditorHelper.PathCombine(Application.dataPath, "Build/CSV/Common");
                    string         path         = JumpCsvEditorHelper.MakeRelativePath(resourcePath, csvFile);
                    CsvSpreadSheet spreadSheet  = new CsvSpreadSheet(path.Replace(".csv", ""), true);                      //string content = reader.ReadToEnd();
                    //csvReader.ReadFromString(content);
                    int CheckSum = spreadSheet.GetHashCode();
                    if (CheckSum != hashCode)
                    {
                        expiredCsvFiles.Add(csvFile);
                    }
                }
            }
            return(expiredCsvFiles.ToArray());
        }
Example #3
0
 public static bool CheckCsvBinDataDirectory(string path)
 {
     if (!Directory.Exists(path))
     {
         return(false);
     }
     return(IsContainParentPath(path, JumpCsvEditorHelper.PathCombine(Application.dataPath, "Resources")));
 }
 public void InitSettingsValues()
 {
     CsvSpreadSheetFileDirectory = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSpreadSheetFileDirectory);
     CsvSourceCodeFileDirectory  = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSourceCodeFileDirectory);
     CsvBinDataDirectory         = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory);
     CsvDataClassPrefixName      = JumpCsvConfig.CsvDataClassPrefixName;
     CsvDataClassPostfixName     = JumpCsvConfig.CsvDataClassPostfixName;
     CsvDataStructPostfixName    = JumpCsvConfig.CsvDataStructPostfixName;
     CsvExtensionNames           = string.Join(";", JumpCsvConfig.CsvExtensionNames.ToArray());
     ExcludeCsvFiles             = string.Join(";", JumpCsvConfig.ExcludeCsvFiles.ToArray());
 }
Example #5
0
        public static void CleanAllFiles()
        {
            // remove all csv data class generated in csv source code folder
            string directory = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvSourceCodeFileDirectory);

            FileUtil.DeleteFileOrDirectory(directory);

            // remove all binary data generated in csv binary data folder
            directory = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory);
            FileUtil.DeleteFileOrDirectory(directory);

            // reset CsvManager.cs file
            JumpCsvCodeGenerator.CreateEmptyCsvManagerSourceFile();
        }
Example #6
0
        public static string[] GetAllLoseCsvData()
        {
            List <string> csvDataFiles = new List <string>();

            foreach (string csvFile in ListAllCsvFilesInCsvFolder())
            {
                string csvDataFileName = JumpCsvEditorHelper.PathCombine(JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory), JumpCsvEditorHelper.GetCsvDataBinaryFileName(csvFile));
                if (!File.Exists(csvDataFileName))
                {
                    csvDataFiles.Add(csvDataFileName);
                }
            }
            return(csvDataFiles.ToArray());
        }
        static void BakeCsv(GameConfig.EShipChannel shipchannel, bool popupResult = false)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            BakeLocalizationCsv();
            CsvManager.isInit = false;
            string directory = JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvConfig.CsvBinDataDirectory);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            CsvManager.Serialize(GameConfig.GetCsvTargetPath(shipchannel));
            AssetDatabase.Refresh();
            if (popupResult)
            {
                EditorUtility.DisplayDialog("成功", "生成csv文件成功。", "Ok");
            }
            Debug.Log("Bake Csv Complete: " + sw.Elapsed.TotalMilliseconds.ToString() + "ms");
        }
        static void BuildLocalization()
        {
            string mapLevelFolder = "Assets/Build/Localization";

            if (!Directory.Exists(mapLevelFolder))
            {
                Directory.CreateDirectory(mapLevelFolder);
            }
            CsvReader.DOUBLEQUOTE = false;
            var csvReader = new CsvReader();

            csvReader.Read("Assets/Build/Localization/Localization.csv");
            CsvReader.DOUBLEQUOTE = true;
            int           idIndex    = -1;
            int           valueIndex = -1;
            List <int>    langList   = new List <int>();
            List <string> langStr    = new List <string>();

            for (int i = 0; i < csvReader.Width; i++)
            {
                if (csvReader.ReadCell(0, i).IndexOf("_ID") >= 0)
                {
                    idIndex = i;
                }
                else if (csvReader.ReadCell(0, i).IndexOf("_VALUE") >= 0)
                {
                    valueIndex = i;
                }
                else if (csvReader.ReadCell(0, i).IndexOf("Comment") < 0)
                {
                    langList.Add(i);
                    langStr.Add(csvReader.ReadCell(0, i).Remove(csvReader.ReadCell(0, i).IndexOf(":")));
                }
            }

            for (int i = 0; i < langList.Count; i++)
            {
                using (StreamWriter sr = new StreamWriter(mapLevelFolder + "/Localization_" + langStr[i] + ".csv", false)) {
                    string valueString = (valueIndex != -1)?",_VALUE":"";
                    sr.WriteLine(csvReader.ReadCell(0, idIndex) + valueString + "," + "text:string");
                    for (int j = 1; j < csvReader.Height; j++)
                    {
                        string id  = csvReader.ReadCell(j, idIndex);
                        string val = (valueIndex != -1)?csvReader.ReadCell(j, valueIndex):(j.ToString());
                        //string val  = csvReader.ReadCell(j, valueIndex);
                        string text = csvReader.ReadCell(j, langList[i]);
                        if (text.IndexOf(",") > 0 ||
                            text.IndexOf("\"") > 0 ||
                            text.IndexOf("\n") > 0 ||
                            text.IndexOf("\r") > 0 ||
                            (text.Length >= 3 && text[0] == '"' && text[1] == '"' && text[2] != '"'))
                        {
                            text = "\"" + text + "\"";
                        }
                        string finalVal = (valueIndex != -1)?("," + val):"";
                        sr.WriteLine(id + finalVal + "," + text);
                    }
                }
            }

            AssetDatabase.Refresh();
            // create localizationcsvdata.cs
            CsvSpreadSheet localizationSheet = new CsvSpreadSheet("Assets/Build/Localization/Localization_CN", true);

            localizationSheet.CsvFileName = "Assets/Build/Localization/Localization";
            var tmpFile = JumpCsvCodeGenerator.CreateCsvDataClassSourceFile2(localizationSheet);

            FileUtil.ReplaceFile(tmpFile, JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvEditorHelper.PathCombine(JumpCsvConfig.CsvSourceCodeFileDirectory, Path.GetFileName(tmpFile))));
            AssetDatabase.Refresh();



//         csvReader = new CsvReader();
//         csvReader.Read("Assets/Build/Localization/RandomName.csv");
//         idIndex = -1;
//         valueIndex = -1;
//         int maleSurname = -1;
//         int maleName = -1;
//         int femaleSurname = -1;
//         int femaleName = -1;
//
//         for(int i = 0; i < csvReader.Width; i++) {
//             if(csvReader.ReadCell(0, i).IndexOf ("_ID") >= 0) {
//                 idIndex = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("_VALUE") >= 0) {
//                 valueIndex = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("MaleSurname") >=0 ) {
//                 maleSurname = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("MaleName") >=0 ) {
//                 maleName = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("FemaleSurname") >=0 ) {
//                 femaleSurname = i;
//             }
//             else if(csvReader.ReadCell(0, i).IndexOf ("FemaleName") >=0 ) {
//                 femaleName = i;
//             }
//         }
//
//         int currentValue = 1;
//         int currentIndex = 0;
//         int currentHeight = 1;
//         for(int i = 0; i < langStr.Count; i++) {
//             using(StreamWriter sr = new StreamWriter(mapLevelFolder + "/RandomName_" + langStr[i] + ".csv", false)) {
//                 sr.WriteLine("_INDEX,MaleSurname:string[],MaleName:string[],FemaleSurname:string[],FemaleName:string[]");
//                 for(int j = currentHeight; j < csvReader.Height; j++, currentIndex++) {
//                     string val = csvReader.ReadCell(j, valueIndex);
//                     if(!string.IsNullOrEmpty(val) && Int32.Parse(val) != currentValue) {
//                         currentValue = Int32.Parse(val);
//                         currentIndex = 0;
//                         currentHeight = j;
//                         break;
//                     }
//                     if(currentIndex == 0) {
//                         sr.WriteLine(currentIndex.ToString() + "," + csvReader.ReadCell(j, maleSurname) + "," + csvReader.ReadCell(j, maleName) + "," + csvReader.ReadCell(j, femaleSurname) + "," + csvReader.ReadCell(j, femaleName));
//                     }
//                     else {
//                         sr.WriteLine("," + csvReader.ReadCell(j, maleSurname) + "," + csvReader.ReadCell(j, maleName) + "," + csvReader.ReadCell(j, femaleSurname) + "," + csvReader.ReadCell(j, femaleName));
//                     }
//                 }
//             }
//         }
//         AssetDatabase.Refresh();
//         // create localizationcsvdata.cs
//         localizationSheet = new CsvSpreadSheet("Assets/Build/Localization/RandomName_CN", true);
//         localizationSheet.CsvFileName = "Assets/Build/Localization/RandomName";
//         tmpFile = JumpCsvCodeGenerator.CreateCsvDataClassSourceFile(localizationSheet);
//         FileUtil.ReplaceFile(tmpFile, JumpCsvEditorHelper.PathCombine(Application.dataPath, JumpCsvEditorHelper.PathCombine(JumpCsvConfig.CsvSourceCodeFileDirectory, Path.GetFileName(tmpFile))));
//         AssetDatabase.Refresh();
        }