Ejemplo n.º 1
0
        /// <summary>
        /// 重新扫描项目并更新目标脚本的信息
        /// </summary>
        /// <param name="option">目标脚本信息</param>
        /// <param name="save">是否扫描完成后自动保存</param>
        public static void RescanScriptInformation(ScriptInformation option, bool save = true)
        {
            var source = option.SourceAssetPath();

            if (!string.IsNullOrEmpty(source))
            {
                if (File.Exists(source))
                {
                    option.hash = Hasher.Crc32(Encoding.UTF8.GetBytes(File.ReadAllText(source, Encoding.UTF8).UnifyLineBreak()));
                }
                else
                {
                    option.hash = null;
                }
            }
            var binary = option.BinaryAssetPath();

            if (!string.IsNullOrEmpty(binary))
            {
                if (File.Exists(source))
                {
                    var stream = new FileStream(binary, FileMode.Open);
                    var hash   = ScriptInformation.ReadBinaryHash(stream);
                    stream.Close();
                    option.recordedHash = hash;
                }
                else
                {
                    option.recordedHash = null;
                }
            }
            var detectedLanguage = new List <string>();

            foreach (var language in Directory.GetDirectories($"Assets/{CompileConfiguration.Content.TranslationFolder}").Select(Path.GetFileName))
            {
                if (File.Exists($"Assets/{CompileConfiguration.Content.TranslationFolder}/{language}/{option.id}.txt"))
                {
                    if (!option.Translations.ContainsKey(language))
                    {
                        option.Translations.Add(language, null);
                    }
                    detectedLanguage.Add(language);
                }
                else
                {
                    if (option.Translations.ContainsKey(language))
                    {
                        option.Translations.Remove(language);
                    }
                }
            }
            var needRemove = new List <string>();

            foreach (var(key, _) in option.Translations)
            {
                if (!detectedLanguage.Contains(key))
                {
                    needRemove.Add(key);
                }
            }
            foreach (var key in needRemove)
            {
                option.Translations.Remove(key);
            }
            if (!option.HasSource() && !option.HasBinary())
            {
                CompileConfiguration.Content.Scripts.Remove(option.id);
            }
            if (save)
            {
                CompileConfiguration.Save();
            }
        }