/// <summary> /// Checks if .index file should be created or not. /// </summary> /// <param name="folderPath"></param> /// <param name="doExeTimeStampCheck">Should exe timestamp check done or not.</param> private static bool TryGetIndex(string folderPath, out MethodIndex index, bool doExeTimeStampCheck = true) { index = null; string indexFilePath = Path.Combine(folderPath, indexFileName); if (!File.Exists(indexFilePath)) { return(false); } index = JsonConvert.DeserializeObject <MethodIndex>(File.ReadAllText(indexFilePath)); var expectedExeTimeStamp = index.LastModifiedTimeOfExe; var actualExeTimeStamp = File.GetLastWriteTimeUtc(Assembly.GetExecutingAssembly().Location); // If exe timestamp check should be done if (doExeTimeStampCheck && expectedExeTimeStamp != actualExeTimeStamp) { return(false); } var timestamps = index.LastModifiedTime; foreach (var fileEntry in timestamps) { string fullFilePath = Path.Combine(folderPath, fileEntry.Key); if (!File.Exists(fullFilePath) || fileEntry.Value != File.GetLastWriteTimeUtc(fullFilePath)) { // recreate index if dasm files timestamp don't match return(false); } } return(true); }
/// <summary> /// Creates .index file based on .dasm files present in <paramref name="folderPath"/>. /// </summary> /// <param name="folderPath"></param> private static MethodIndex CreateIndex(string folderPath) { if (!Directory.Exists(folderPath)) { throw new DirectoryNotFoundException($"Direction {folderPath} not found."); } stopWatch.Restart(); var timestamps = new Dictionary <string, DateTime>(); var methodDatabase = new MethodDB(); MethodIndex index = new MethodIndex(File.GetLastWriteTimeUtc(Assembly.GetExecutingAssembly().Location), timestamps, methodDatabase); var dasmFiles = Directory.GetFiles(folderPath, "*.dasm", SearchOption.TopDirectoryOnly); foreach (var dasmFile in dasmFiles) { index.AddFile(dasmFile); } string contents = JsonConvert.SerializeObject(index); File.WriteAllText(Path.Combine(folderPath, indexFileName), contents); stopWatch.Stop(); Console.WriteLine($"Index created in {stopWatch.Elapsed.TotalSeconds} secs."); return(index); }