static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Application.Run(new Replicate()); } catch (Exception e) { LogControl.Write($"Opps!! something went wrong!!: { e.Message}"); } }
/// <summary> /// View log file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnViewlog_Click(object sender, EventArgs e) { try { _Path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string LoggerFileName = Path.Combine( _Path, "log.txt"); System.Diagnostics.Process.Start("notepad.exe", LoggerFileName); } catch (Exception ex) { LogControl.Write($"Error! {ex.Message}"); } }
/// <summary> /// Copy folder and files to destination /// </summary> /// <param name="sourceFolder"></param> /// <param name="destFolder"></param> /// <param name="includeSubDir"></param> public static async Task CopyFolder(string sourceFolder, string destFolder, bool includeSubDir) { try { if (Directory.Exists(destFolder) && !Directory.Exists(sourceFolder)) { Directory.Delete(destFolder); } if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } if (includeSubDir) { string[] folders = Directory.GetDirectories(sourceFolder); foreach (string folder in folders) { string name = Path.GetFileName(folder); string dest = Path.Combine(destFolder, name); LogControl.Write($"Copy from: {folder} To: {dest}"); await CopyFolder(folder, dest, includeSubDir); } } if (File.Exists(destFolder) && !File.Exists(sourceFolder)) { File.Delete(destFolder); } CopyFile(sourceFolder, destFolder); } catch (Exception ex) { LogControl.Write($"Error! {ex.Message}"); } }
/// <summary> /// button event to replicate /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ReplicateBtn_Click(object sender, EventArgs e) { try { var source = sourcePathTxt.Text ?? Settings.Default.SourcePath; var dest = destPathTxt.Text ?? Settings.Default.DestPath; var progress = progressBar.BeginInvoke( new Action(async() => { progressBar.Style = ProgressBarStyle.Marquee; progressBar.Value = 50; await Directories.CopyFolder(source, dest, subDirchkBox.Checked); progressBar.Value = 0; } )); Reset(); } catch (Exception ex) { LogControl.Write($"Error! {ex.Message}"); } }