private void UpdateLiteralReplacer(string fl, CompleteVersion versonToWrite, DisplayType dtx) { #if DEBUG if (!File.Exists(fl)) { throw new InvalidOperationException("Must not be possible, check this before you reach this code"); } #endif Func <string, string> replacer; if (dtx == DisplayType.NoDisplay) { replacer = new Func <string, string>((inney) => { return(inney.Replace("XXX-RELEASENAME-XXX", versonToWrite.ReleaseName)); }); } else { replacer = new Func <string, string>((inney) => { return(inney.Replace("XXX-RELEASENAME-XXX", versonToWrite.ReleaseName) .Replace("XXX-VERSION-XXX", versonToWrite.GetVersionString(dtx)) .Replace("XXX-VERSION3-XXX", versonToWrite.GetVersionString(DisplayType.ThreeDigit)) .Replace("XXX-VERSION2-XXX", versonToWrite.GetVersionString(DisplayType.Short))); }); } string fileText = replacer(File.ReadAllText(fl)); File.WriteAllText(fl, fileText); }
public void PerformUpdate(string fl, FileUpdateType fut, DisplayType dt = DisplayType.Default) { b.Verbose.Log("Perform update requested " + fut.ToString(), fl); if (!File.Exists(fl)) { throw new FileNotFoundException($"Filename must be present for version update {fl}"); } var dtx = cv.GetDisplayType(fut, dt); string versonToWrite = cv.GetVersionString(dtx); switch (fut) { case FileUpdateType.NetAssembly: UpdateCSFileWithAttribute(fl, ASMFILE_VER_TAG, versonToWrite); break; case FileUpdateType.NetInformational: UpdateCSFileWithAttribute(fl, ASMFILE_INFVER_TAG, versonToWrite); break; case FileUpdateType.NetFile: UpdateCSFileWithAttribute(fl, ASMFILE_FILEVER_TAG, versonToWrite); break; case FileUpdateType.Wix: UpdateWixFile(fl, versonToWrite); break; case FileUpdateType.Nuspec: UpdateNuspecFile(fl, versonToWrite); break; case FileUpdateType.StdAssembly: UpdateStdCSPRoj(fl, versonToWrite, ASM_STD_ASMVTAG); break; case FileUpdateType.StdFile: UpdateStdCSPRoj(fl, versonToWrite, ASM_STD_FILETAG); break; case FileUpdateType.StdInformational: UpdateStdCSPRoj(fl, versonToWrite, ASM_STD_VERSTAG); break; case FileUpdateType.TextFile: UpdateLiteralReplacer(fl, cv, dtx); break; default: throw new NotImplementedException("The file type requested does not have a way to update files currently."); } }
public void IncrementAndUpdateAll() { b.Verbose.Log("IncrementAndUpdateAll called"); ValidateForUpdate(); LoadVersioningComponent(); b.Verbose.Log("Versioning Loaded "); ver.Increment(); b.Verbose.Log("Saving"); SaveVersioningComponent(); b.Verbose.Log($"Searching {BaseSearchDir} there are {pendingUpdates.Count} pends."); var enumer = Directory.EnumerateFiles(BaseSearchDir, "*.*", SearchOption.AllDirectories).GetEnumerator(); bool shouldContinue = true; while (shouldContinue) { try { shouldContinue = enumer.MoveNext(); if (shouldContinue) { var v = enumer.Current; // Check every file that we have returned. foreach (var chk in pendingUpdates.Keys) { var mm = new Minimatcher(chk, new Options { AllowWindowsPaths = true, IgnoreCase = true }); b.Verbose.Log($"Checking {chk} against {v}"); if (mm.IsMatch(v)) { b.Info.Log("Match..."); // TODO Cache this and make it less loopey VersionFileUpdater sut = new VersionFileUpdater(ver); foreach (var updateType in pendingUpdates[chk]) { b.Verbose.Log($"Perform update {v}"); sut.PerformUpdate(v, updateType); } } } } } catch (System.UnauthorizedAccessException) { // If you run through all the filles in a directory you can hit areas of the filesystem // that you dont have access to - this skips those files and then continues. b.Verbose.Log("Unauthorised area of the filesystem, skipping"); } } VersionString = ver.GetVersionString(); }