/// <summary>
        /// 收集StringsTalbe.bytes的字符串
        /// </summary>
        /// <param name="refItems"></param>
        static void CollectStringsTable(ref I18NItems refItems)
        {
            var compilePath = AppEngine.GetConfig("KEngine.Setting", "SettingCompiledPath");
            var ext = AppEngine.GetConfig("KEngine", "AssetBundleExt");
            var stringsTablePath = string.Format("{0}/StringsTable{1}", compilePath, ext);
            if (!File.Exists(stringsTablePath))
                return;

            string stringsTableContent;
            using (var stream = new FileStream(stringsTablePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var reader = new StreamReader(stream))
                {
                    stringsTableContent = reader.ReadToEnd();
                }
            }

            var tableFile = new TableFile(stringsTableContent);
            foreach (var row in tableFile)
            {
                var srcStr = row["Id"];
                refItems.Add(srcStr, stringsTablePath);
            }
            Debug.Log("[CollectStringsTable]Success!");
        }
Esempio n. 2
0
        //[MenuItem("KEngine/I18N/Collect All")]
        public static void CollectAll()
        {
            // 如果没有,先确保创建新的
            foreach (var lang in AppConfig.I18NLanguages)
            {
                var xlsPath = string.Format("{0}/I18N/{1}.xlsx", AppConfig.SettingSourcePath, lang);
                var xlsDir  = Path.GetDirectoryName(xlsPath);
                if (!Directory.Exists(xlsDir))
                {
                    Directory.CreateDirectory(xlsDir);
                }

                if (!File.Exists(xlsPath))
                {
                    // Id	Value	CommentSrcFile
                    CreateExcel(xlsPath);
                }
            }

            var refList    = new I18NItems(); // key, 和 来源
            var collectors = FindCollectors();

            if (collectors.Count == 0)
            {
                throw new Exception("No I18N Collectors found, write your custom `I18NInterface` class");
            }
            foreach (var collector in collectors)
            {
                collector.Collect(ref refList);
            }

            WriteExcel(refList);
        }
Esempio n. 3
0
        /// <summary>
        /// 收集StringsTalbe.bytes的字符串
        /// </summary>
        /// <param name="refItems"></param>
        static void CollectStringsTable(ref I18NItems refItems)
        {
            var compilePath      = AppEngine.GetConfig("KEngine.Setting", "SettingCompiledPath");
            var ext              = AppEngine.GetConfig("KEngine", "AssetBundleExt");
            var stringsTablePath = string.Format("{0}/StringsTable{1}", compilePath, ext);

            if (!File.Exists(stringsTablePath))
            {
                return;
            }

            string stringsTableContent;

            using (var stream = new FileStream(stringsTablePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var reader = new StreamReader(stream))
                {
                    stringsTableContent = reader.ReadToEnd();
                }
            }

            var tableFile = new TableFile(stringsTableContent);

            foreach (var row in tableFile)
            {
                var srcStr = row["Id"];
                refItems.Add(srcStr, stringsTablePath);
            }
            Debug.Log("[CollectStringsTable]Success!");
        }
 public void Collect(ref I18NItems i18List)
 {
     CollectStringsTable(ref i18List);
 }
Esempio n. 5
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="theList"></param>
        /// <returns></returns>
        private static bool WriteExcel(I18NItems theList)
        {
            foreach (var lang in AppConfig.I18NLanguages)
            {
                var excelPath = string.Format("{0}/I18N/{1}.xlsx", AppConfig.SettingSourcePath, lang);

                var       changedFile = false;
                ExcelFile excelFile;
                try
                {
                    excelFile = new ExcelFile(excelPath);
                }
                catch (IOException e)
                {
                    Debug.LogError("无法打开Excel,是否正在编辑: " + excelPath + " " + e.Message);
                    return(false);
                }
                // 把表中的值缓存起来! 方便查询是否已经存在过了!
                var id2RowMap     = new Dictionary <string, int>();
                var excelRowCount = excelFile.GetRowsCount();
                for (int row = 3; row < excelRowCount; row++) // 跳过前3行
                {
                    var key = excelFile.GetString("Id", row);
                    id2RowMap[key] = row;
                }

                var rowCount = excelFile.GetRowsCount();

                // 存在的不动,不存在的添加
                HashSet <string> useList = new HashSet <string>(); // 用来缓存处理过的,后面把旧的标记出来方便后面删
                foreach (var kv in theList.Items)
                {
                    var newKey   = kv.Key;
                    var srcsList = kv.Value; // 来源,几个字符串来源
                    int existRow;
                    if (!id2RowMap.TryGetValue(newKey, out existRow))
                    {
                        existRow = rowCount++;
                        excelFile.SetRow("Id", existRow, newKey);
                        changedFile = true;
                    }

                    // 来源列, 覆盖上去
                    //var sourcesStr = excelFile.GetString("CommentSrcFile", existRow);
                    //var existStrsList = CTool.Split<string>(sourcesStr, '|');
                    //var unionStrs = existStrsList.Union(srcsList);
                    var srcStr        = string.Join("|", srcsList.ToArray());
                    var srcStrInExcel = excelFile.GetString("CommentSrcFile", existRow);
                    if (srcStr != srcStrInExcel)
                    {
                        excelFile.SetRow("CommentSrcFile", existRow, srcStr);
                        changedFile = true;
                    }

                    // 已存在,不处理,添加到列表,后面检测没用的
                    useList.Add(newKey);
                }

                // useList 和 theList做差集,找出没用的!
                if (id2RowMap.Count > useList.Count)
                {
                    var exceptList = id2RowMap.Keys.Except(useList);
                    //var exceptList2 = useList.Except(id2RowMap.Keys);
                    //var exCount = exceptList.Count();
                    foreach (var exceptStr in exceptList)
                    {
                        var exceptRow = id2RowMap[exceptStr];
                        Log.Info("多出来的: {0}, 旧的,所在行 {1}, 删除!", exceptStr, exceptRow);
                        //excelFile.SetRowGrey(exceptRow);
                        excelFile.ClearRow(exceptRow);
                        changedFile = true;
                    }
                }
                if (changedFile) // 有修改的才保存
                {
                    excelFile.Save();
                }
                Log.Info("Write Excel: {0}", excelPath);
            }
            return(true);
        }
Esempio n. 6
0
 public void Collect(ref I18NItems i18List)
 {
     CollectStringsTable(ref i18List);
 }
Esempio n. 7
0
        public static void CollectAll()
        {
            // 如果没有,先确保创建新的
            foreach (var lang in I18NLanguages)
            {
                var xlsPath = string.Format("{0}/I18N/{1}.xlsx", SettingSourcePath, lang);
                var xlsDir = Path.GetDirectoryName(xlsPath);
                if (!Directory.Exists(xlsDir))
                    Directory.CreateDirectory(xlsDir);

                if (!File.Exists(xlsPath))
                {
                    // Id	Value	CommentSrcFile
                    CreateExcel(xlsPath);
                }
            }

            var refList = new I18NItems(); // key, 和 来源
            var collectors = FindCollectors();
            if (collectors.Count == 0)
                throw new Exception("No I18N Collectors found, write your custom `I18NInterface` class");
            foreach (var collector in collectors)
            {
                collector.Collect(ref refList);
            }

            WriteExcel(refList);
        }
Esempio n. 8
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="theList"></param>
        /// <returns></returns>
        private static bool WriteExcel(I18NItems theList)
        {
            foreach (var lang in I18NLanguages)
            {
                var excelPath = string.Format("{0}/I18N/{1}.xlsx", SettingSourcePath, lang);

                var changedFile = false;
                ExcelFile excelFile;
                try
                {
                    excelFile = new ExcelFile(excelPath);
                }
                catch (IOException e)
                {
                    Debug.LogError("无法打开Excel,是否正在编辑: " + excelPath + " " + e.Message);
                    return false;

                }
                // 把表中的值缓存起来! 方便查询是否已经存在过了!
                var id2RowMap = new Dictionary<string, int>();
                var excelRowCount = excelFile.GetRowsCount();
                for (int row = 3; row < excelRowCount; row++) // 跳过前3行
                {
                    var key = excelFile.GetString("Id", row);
                    id2RowMap[key] = row;
                }

                var rowCount = excelFile.GetRowsCount();

                // 存在的不动,不存在的添加
                HashSet<string> useList = new HashSet<string>(); // 用来缓存处理过的,后面把旧的标记出来方便后面删
                foreach (var kv in theList.Items)
                {
                    var newKey = kv.Key;
                    var srcsList = kv.Value; // 来源,几个字符串来源
                    int existRow;
                    if (!id2RowMap.TryGetValue(newKey, out existRow))
                    {
                        existRow = rowCount++;
                        excelFile.SetRow("Id", existRow, newKey);
                        changedFile = true;
                    }

                    // 来源列, 覆盖上去
                    //var sourcesStr = excelFile.GetString("CommentSrcFile", existRow);
                    //var existStrsList = CTool.Split<string>(sourcesStr, '|');
                    //var unionStrs = existStrsList.Union(srcsList);
                    var srcStr = string.Join("|", srcsList.ToArray());
                    var srcStrInExcel = excelFile.GetString("CommentSrcFile", existRow);
                    if (srcStr != srcStrInExcel)
                    {
                        excelFile.SetRow("CommentSrcFile", existRow, srcStr);
                        changedFile = true;
                    }

                    // 已存在,不处理,添加到列表,后面检测没用的
                    useList.Add(newKey);
                }

                // useList 和 theList做差集,找出没用的!
                if (id2RowMap.Count > useList.Count)
                {
                    var exceptList = id2RowMap.Keys.Except(useList);
                    //var exceptList2 = useList.Except(id2RowMap.Keys);
                    //var exCount = exceptList.Count();
                    foreach (var exceptStr in exceptList)
                    {
                        var exceptRow = id2RowMap[exceptStr];
                        Log.Info("多出来的: {0}, 旧的,所在行 {1}, 删除!", exceptStr, exceptRow);
                        //excelFile.SetRowGrey(exceptRow);
                        excelFile.ClearRow(exceptRow);
                        changedFile = true;
                    }

                }
                if (changedFile) // 有修改的才保存
                    excelFile.Save();
                Log.Info("Write Excel: {0}", excelPath);
            }
            return true;
        }