Copy function && Separate function for everything
This commit is contained in:
parent
263f69b2b8
commit
fd07d1ce74
@ -1,5 +1,6 @@
|
|||||||
public class Program {
|
public class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
|
string result = Update.copyEverthingToBackup();
|
||||||
|
Console.WriteLine(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
36
Update.cs
36
Update.cs
@ -1,21 +1,23 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
public class Update {
|
public class Update {
|
||||||
public string homePath { get; set; } = string.Empty;
|
public static string getHomePath() {
|
||||||
public void getHomePath() {
|
string homePath = string.Empty;
|
||||||
|
|
||||||
if(Environment.OSVersion.Platform == PlatformID.Unix) {
|
if(Environment.OSVersion.Platform == PlatformID.Unix) {
|
||||||
homePath = Environment.GetEnvironmentVariable("HOME");
|
homePath = Environment.GetEnvironmentVariable("HOME");
|
||||||
|
return homePath;
|
||||||
} else {
|
} else {
|
||||||
Console.WriteLine("This script doesn't support your operating system.");
|
throw new ApplicationException("This script doesn't support your operating system.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startUpdate() {
|
public static void startUpdate() {
|
||||||
Process process = new Process();
|
Process process = new Process();
|
||||||
|
|
||||||
ProcessStartInfo processStartInfo = new ProcessStartInfo();
|
ProcessStartInfo processStartInfo = new ProcessStartInfo();
|
||||||
//processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
//processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||||
processStartInfo.FileName = @"yay";
|
processStartInfo.FileName = @"yay";
|
||||||
processStartInfo.WorkingDirectory = homePath;
|
processStartInfo.WorkingDirectory = getHomePath();
|
||||||
//processStartInfo.Arguments = "--color";
|
//processStartInfo.Arguments = "--color";
|
||||||
processStartInfo.RedirectStandardOutput = false;
|
processStartInfo.RedirectStandardOutput = false;
|
||||||
processStartInfo.RedirectStandardError = false;
|
processStartInfo.RedirectStandardError = false;
|
||||||
@ -23,5 +25,29 @@ public class Update {
|
|||||||
|
|
||||||
process.StartInfo = processStartInfo;
|
process.StartInfo = processStartInfo;
|
||||||
process.Start();
|
process.Start();
|
||||||
|
|
||||||
|
process.StandardInput.WriteLine(" ");
|
||||||
|
|
||||||
|
//shellStream.WriteLine("passwd fadwa");
|
||||||
|
//shellStream.Expect("Enter new password:");
|
||||||
|
//shellStream.WriteLine("fadwa");
|
||||||
|
//shellStream.Expect("Retype new password:");
|
||||||
|
//shellStream.WriteLine("fadwa");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string copyEverthingToBackup() {
|
||||||
|
string fileName = "fstab";
|
||||||
|
string sourcePath = @"/etc/";
|
||||||
|
string targetPath = getHomePath();
|
||||||
|
|
||||||
|
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
|
||||||
|
string destFile = System.IO.Path.Combine(targetPath, fileName);
|
||||||
|
|
||||||
|
System.IO.Directory.CreateDirectory(targetPath);
|
||||||
|
|
||||||
|
System.IO.File.Copy(sourceFile, destFile, true);
|
||||||
|
|
||||||
|
return $"Copied {fileName} to {targetPath}";
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user