using System; using System.Collections.Generic; using System.Text; using System.IO; namespace SL_Switcher { public class FileCopy : FileOperation { private string m_source_root; public FileCopy(string srcroot, string dstroot, string filename) : base(dstroot,filename) { this.SourceRoot = srcroot; } public string Source { get { return Path.Combine(m_source_root, this.Filename); } } public override void Execute() { Directory.CreateDirectory(Path.GetDirectoryName(this.Destination)); File.Copy(this.Source, this.Destination, true); DateTime writetime = File.GetLastWriteTime(this.Destination); File.SetLastWriteTime(this.Destination, writetime); } public override string ToString() { return "Copy " + this.Source + " to " + this.Destination; } public override int ProgressValue { get { FileInfo fi = new FileInfo(this.Source); return (int)fi.Length; } } public string SourceRoot { get { return m_source_root;} set { m_source_root = value;} } public override bool ActionNeeded() { if (!File.Exists(this.Destination)) { return true; } FileInfo src = new FileInfo(this.Source); FileInfo dst = new FileInfo(this.Destination); return ((src.Length != dst.Length) || (src.LastWriteTime != dst.LastWriteTime)); } // override } }