From fd07d1ce747ea32dcf259a4c3fe6d471c0ff3785 Mon Sep 17 00:00:00 2001 From: FUH22860 Date: Tue, 6 Dec 2022 12:23:45 +0100 Subject: [PATCH] Copy function && Separate function for everything --- Program.cs | 3 ++- Update.cs | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Program.cs b/Program.cs index 5cefd27..61e9274 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,6 @@ public class Program { static void Main(string[] args) { - + string result = Update.copyEverthingToBackup(); + Console.WriteLine(result); } } \ No newline at end of file diff --git a/Update.cs b/Update.cs index c0331b4..53e089f 100644 --- a/Update.cs +++ b/Update.cs @@ -1,21 +1,23 @@ using System.Diagnostics; public class Update { - public string homePath { get; set; } = string.Empty; - public void getHomePath() { + public static string getHomePath() { + string homePath = string.Empty; + if(Environment.OSVersion.Platform == PlatformID.Unix) { homePath = Environment.GetEnvironmentVariable("HOME"); + return homePath; } 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(); ProcessStartInfo processStartInfo = new ProcessStartInfo(); //processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; processStartInfo.FileName = @"yay"; - processStartInfo.WorkingDirectory = homePath; + processStartInfo.WorkingDirectory = getHomePath(); //processStartInfo.Arguments = "--color"; processStartInfo.RedirectStandardOutput = false; processStartInfo.RedirectStandardError = false; @@ -23,5 +25,29 @@ public class Update { process.StartInfo = processStartInfo; 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}"; } } \ No newline at end of file