// 拷贝并缩放文件 void ConvertFiles(string srcPath, int sw, int sh, string destPath, int dw, int dh) { // 源文件列表 List <string> srcFiles = new List <string>(); try { bool ignoreCopy = (srcPath.ToLower() == destPath.ToLower()); // 建立目录并获取文件列表 CreateDir(srcPath, destPath, srcFiles); // 建立图片转换配置,用于记录需要转换的图片文件,其他文件则直接拷贝 ResConfig resource = new ResConfig(); resource.path = srcPath; resource.name = WizardConfig.NAME_DEFAULT_THEME; // 遍历所有文件 int cutLen = srcPath.Length; foreach (string srcfile in srcFiles) { // 截掉模板目录以径获取相对路径 string relFile = srcfile.Substring(cutLen + 1); // 取得扩展名 string ext = Path.GetExtension(relFile).ToLower(); if ( // 宽高如果和源文件相同那就不用转换了 (sw != dw || sh != dh) && // 忽略某些图片 !WizardConfig.IgnorePicture(relFile) && // 只转换这些扩展名对应的文件 (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".bmp")) { // 是图片则添加到转换器中 resource.files.Add(new ResFile(relFile)); } else if (!ignoreCopy) { // 直接拷贝 OnLogging(string.Format("拷贝{0}", relFile)); File.Copy(srcfile, Path.Combine(destPath, relFile), true); } } OnLogging("图片转换中……"); if (resource.files.Count > 0) { // 调用资源转换器方法,并开始转换 Start(resource, destPath, sw, sh, dw, dh); } } catch (System.Exception e) { Console.WriteLine(e.Message); } }
public WizardConverter(WizardConfig config) { _config = config; }