public static void UpdateIndexFile(string[] paths, ref IndexFile index) { if (paths == null) { throw new ArgumentNullException("paths"); } if (index == null) { throw new ArgumentNullException("index"); } log.Info("Refreshing index file."); Hashtable fileLib = RefreshIndexFile(ref index); foreach (string path in paths) { if (Directory.Exists(path)) { log.DebugFormat("Scanning: {0}", path); string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); foreach (string file in files) { bool isDupe = false; FileInfo fi = new FileInfo(file); foreach (DesignFormat df in FileManager.AvailableFormats) { if (df.Equals(fi.FullName)) { log.DebugFormat("The file {0} is a {1}", file, df.Name); log.DebugFormat("Hashing file: {0}", file); string hash = md5(file); log.Debug(hash); DataFile newFile = null; if (fileLib.ContainsKey(hash)) { isDupe = true; newFile = (DataFile)fileLib[hash]; log.DebugFormat("The hash is already in the index for: {0}", newFile.FilePath); if (newFile.FilePath != fi.FullName) { bool exists = false; foreach (DuplicateFile dupe in newFile.DuplicateFiles) { if (fi.FullName == dupe.FilePath) { exists = true; break; } } if (!exists) { newFile.DuplicateFiles.Add(new DuplicateFile(fi.Name, fi.FullName)); } } } else { log.DebugFormat("Adding new file {0}.", fi.Name); newFile = new DataFile(fi.Name, fi.FullName); newFile.FileHash = hash; newFile.Status = FileStatus.InLibrary; newFile.SvgPath = createSvg(df.Format, fi.FullName); newFile.IconPath = createIcon(newFile.SvgPath); index.DataFiles.Add(newFile); fileLib.Add(hash, newFile); } } df.Format.CloseFile(); } } } } SaveIndexFile(index, Embroidr.UI.Configuration.IndexFilePath); }
public static void UpdateIndexFile(string[] paths, ref IndexFile index) { if (paths == null) throw new ArgumentNullException("paths"); if (index == null) throw new ArgumentNullException("index"); log.Info("Refreshing index file."); Hashtable fileLib = RefreshIndexFile(ref index); foreach (string path in paths) { if (Directory.Exists(path)) { log.DebugFormat("Scanning: {0}", path); string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); foreach (string file in files) { bool isDupe = false; FileInfo fi = new FileInfo(file); foreach (DesignFormat df in FileManager.AvailableFormats) { if (df.Equals(fi.FullName)) { log.DebugFormat("The file {0} is a {1}", file, df.Name); log.DebugFormat("Hashing file: {0}", file); string hash = md5(file); log.Debug(hash); DataFile newFile = null; if (fileLib.ContainsKey(hash)) { isDupe = true; newFile = (DataFile)fileLib[hash]; log.DebugFormat("The hash is already in the index for: {0}", newFile.FilePath); if (newFile.FilePath != fi.FullName) { bool exists = false; foreach (DuplicateFile dupe in newFile.DuplicateFiles) { if (fi.FullName == dupe.FilePath) { exists = true; break; } } if (!exists) newFile.DuplicateFiles.Add(new DuplicateFile(fi.Name, fi.FullName)); } } else { log.DebugFormat("Adding new file {0}.", fi.Name); newFile = new DataFile(fi.Name, fi.FullName); newFile.FileHash = hash; newFile.Status = FileStatus.InLibrary; newFile.SvgPath = createSvg(df.Format, fi.FullName); newFile.IconPath = createIcon(newFile.SvgPath); index.DataFiles.Add(newFile); fileLib.Add(hash, newFile); } } df.Format.CloseFile(); } } } } SaveIndexFile(index, Embroidr.UI.Configuration.IndexFilePath); }