This repository was archived by the owner on Mar 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProjectFile.cake
More file actions
56 lines (43 loc) · 1.32 KB
/
Copy pathProjectFile.cake
File metadata and controls
56 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class ProjectFile
{
public ProjectFile(ICakeContext context, string name)
{
Context = context;
Name = name;
}
private ICakeContext Context { get; set; }
public string Name { get; private set; }
public FilePath Path
{
get { return string.Format("./src/{0}/{0}.csproj", Name); }
}
public FilePath BackupPath
{
get { return Path.AppendExtension(".projfile.bak"); }
}
public bool BackupExists
{
get { return Context.FileExists(BackupPath); }
}
public void Restore()
{
if(!BackupExists) return;
Context.Information("Restoring " + Name);
Context.DeleteFile(Path);
Context.MoveFile(BackupPath, Path);
}
public void Backup()
{
if(BackupExists) Restore();
Context.Information("Backing up " + Name);
Context.CopyFile(Path, BackupPath);
}
public void Replace(string pattern, string replacement)
{
var abs = Context.MakeAbsolute(Path).FullPath;
var content = System.IO.File.ReadAllText(abs);
var regex = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.Multiline);
content = regex.Replace(content, replacement);
System.IO.File.WriteAllText(abs, content);
}
}