Ejemplo n.º 1
0
 private void TryFillWord(string word, string fn, int lineNumber, int pos, bool c255, bool ignoreSuffixNumber)
 {
     if (!IsNumber(word))
     {
         if (ignoreSuffixNumber)
         {
             word = RemoveSuffixNumber(word);
         }
         if (word.Length > (c255 ? 1 : 2) && !cfg.safes.Contains(word))
         {
             ReplaceToFileLineNumberFromTo fileLineNumbers;
             Dictionary <int, List <int> > lineNumbers;
             List <int> idxs;
             if (!words.TryGetValue(word, out fileLineNumbers))
             {
                 fileLineNumbers           = new ReplaceToFileLineNumberFromTo();
                 fileLineNumbers.replaceTo = word;
                 words.Add(word, fileLineNumbers);
             }
             if (!fileLineNumbers.fileLineNumbers.TryGetValue(fn, out lineNumbers))
             {
                 lineNumbers = new Dictionary <int, List <int> >();
                 fileLineNumbers.fileLineNumbers.Add(fn, lineNumbers);
             }
             if (!lineNumbers.TryGetValue(lineNumber, out idxs))
             {
                 idxs = new List <int>();
                 lineNumbers.Add(lineNumber, idxs);
             }
             idxs.Add(pos);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 将指定目录下所有 资源文件 文件名( 表层 ) 塞到 words
        /// </summary>
        private void FillRess(string dir)
        {
            var fs = Directory.EnumerateFiles(dir, "*", SearchOption.TopDirectoryOnly).ToArray();

            dir = dir.Replace("/", "\\").Replace("\\\\", "\\");
            foreach (var f in fs)
            {
                var path = f.Replace("/", "\\").Replace("\\\\", "\\");

                // 顺便检查 路径, 文件名 是否符合规范( 全小写_蛇 )
                var tmp = path.Substring(dir.Length).Replace("\\", "").Replace(".", "");
                if (tmp.Any(o => !(o >= '0' && o <= '9' || o >= 'a' && o <= 'z' || o == '_')))
                {
                    warnings.Add("bad res path( 0-9 a-z _ ): " + path);
                }

                var s   = path;
                var ext = GetFileExt(s).ToLower();
                if (cfg.resExts.Contains(ext))
                {
                    s = s.Substring(0, s.Length - ext.Length);
                    var i = s.LastIndexOf('\\');
                    s = s.Substring(i + 1);
                    {
                        var word = s;
                        if (!cfg.safes.Contains(word))
                        {
                            ReplaceToFileLineNumberFromTo fileLineNumbers;
                            if (!words.TryGetValue(word, out fileLineNumbers))
                            {
                                fileLineNumbers           = new ReplaceToFileLineNumberFromTo();
                                fileLineNumbers.replaceTo = word;
                                words.Add(word, fileLineNumbers);
                            }
                            fileLineNumbers.resFilePaths.Add(path);
                        }
                    }

                    // 目录名 切割后 纳入 words
                    var subPath = path.Substring(dir.Length, path.Length - dir.Length - s.Length - ext.Length);
                    var ww      = subPath.Split(new char[] { '\\', '.' }, StringSplitOptions.RemoveEmptyEntries);
                    if (ww.Length > 0)
                    {
                        foreach (var word in ww)
                        {
                            if (!cfg.safes.Contains(word))
                            {
                                ReplaceToFileLineNumberFromTo fileLineNumbers;
                                if (!words.TryGetValue(word, out fileLineNumbers))
                                {
                                    fileLineNumbers           = new ReplaceToFileLineNumberFromTo();
                                    fileLineNumbers.replaceTo = word;
                                    words.Add(word, fileLineNumbers);
                                }
                                fileLineNumbers.resFilePaths.Add(subPath);
                            }
                        }
                    }

                    // 如果该资源文件是代码,就提取内容 words
                    if (cfg.exts.Contains(ext))
                    {
                        FillFileWords2(f);
                    }
                }
            }
        }