public void Clear() { foreach (var lst in ResInfos.Values) { foreach (var res in lst) { res.Unload(); } } ResInfos.Clear(); }
private void LoadPath(string dir) { if (!Directory.Exists(dir)) { return; } var files = Directory.GetFiles(dir); foreach (var file in files) { if (IsFileNameValid(file)) { var info = System.Activator.CreateInstance(ResourceInfo.ResTypes[ResKind], this, file) as ResourceInfo; if (!ResInfos.ContainsKey(info.SubPath)) { ResInfos[info.SubPath] = new List <ResourceInfo> { info } } ; else { var lst = ResInfos[info.SubPath]; bool exist = false; foreach (var r in lst) { if (r.SubPathFileName == info.SubPathFileName) { exist = true; break; } } if (!exist) { ResInfos[info.SubPath].Add(info); } } } } var dirs = Directory.GetDirectories(dir); foreach (var subdir in dirs) { LoadPath(subdir); } }
public ResourceInfo GetResourceInfo(string relativePath) { if (ResourceInfo.ResTypes[ResKind] == typeof(ResourceInfo_Dummy)) { return(System.Activator.CreateInstance(ResourceInfo.ResTypes[ResKind], ResKind) as ResourceInfo); } relativePath = relativePath.Replace("\\\\", "\\"); string name = Path.GetFileName(relativePath); string subdir = Path.GetDirectoryName(relativePath).TrimEnd('\\') + "\\"; string fullfile = RootPath + relativePath; fullfile = fullfile.Replace("\\\\", "\\"); if (!File.Exists(fullfile)) { fullfile = SearchResourceFile(name); if (!File.Exists(fullfile)) { AppLogger.Write(String.Format("错误:未能找到资源文件<{0}>!", RootPath + relativePath)); return(null); } else { name = Path.GetFileName(fullfile); subdir = Path.GetDirectoryName(fullfile.Substring(RootPath.Length)).TrimEnd('\\') + "\\"; AppLogger.Write(String.Format("警告:资源文件<{0}>在路径中不存在,已重定位至<{1}>!", RootPath + relativePath, fullfile)); } } List <ResourceInfo> lst = null; if (ResInfos.TryGetValue(subdir, out lst)) { foreach (var res in lst) { if (res.FileName == name) { return(res); } } } return(null); }