void Copy() { MyLib.Clausa1D TempoSwitcher = new Clausa1D(); TempoSwitcher.SetMinMax(0, 1); TempoSwitcher.Set(NumberPart.Get()); TempoSwitcher.Do(1, 0); List <string> Names = Partes[NumberPart.Get()].GetNames(); string From = Partes[NumberPart.Get()].GetCurrentPath(); string To = Partes[TempoSwitcher.Get()].GetCurrentPath(); if (Names.Count > 0) { List <Global.Types> FromTypes = Partes[NumberPart.Get()].GetTypes(); for (int i = 0; i < Names.Count; ++i) { DoCopy(From, To, Names[i], FromTypes[i]); } Partes[NumberPart.Get()].PrepareDirectory(); Partes[NumberPart.Get()].Reset(); Partes[TempoSwitcher.Get()].PrepareDirectory(); return; } Global.Types CurrentType = Partes[NumberPart.Get()].GetType(); string CurrentName = Partes[NumberPart.Get()].GetName(); DoCopy(From, To, CurrentName, CurrentType); Partes[NumberPart.Get()].PrepareDirectory(); Partes[NumberPart.Get()].Reset(); Partes[TempoSwitcher.Get()].PrepareDirectory(); }
void DoCopy(string FromPath, string ToPath, string Name, Global.Types CurrentType) { string SourcePath = Path.Combine(FromPath, Name); string DestinationPath = Path.Combine(ToPath, Name); if (CurrentType == Global.Types.File) { try { File.Copy(SourcePath, DestinationPath, true); Global.AddToLogFile($"From {FromPath} To {ToPath}", $"Copied File {Name}", "Success"); Global.Attention.AddContent(MyFunc.Set(2, 1), $"Successfully Copied File {SourcePath} To {ToPath}"); } catch (UnauthorizedAccessException) { Global.Attention.AddContent(MyFunc.Set(2, 1), "Access Denied"); Global.AddToLogFile(SourcePath, "Trying to Copy File", "Access Denied"); } catch (Exception) { Global.Attention.AddContent(MyFunc.Set(2, 1), "Can not Copy File"); Global.AddToLogFile(SourcePath, "Trying to Copy File", "Can not Copy File"); } return; } if (CurrentType == Global.Types.Directory) { try { CopyDirectory(FromPath, ToPath, Name); Global.AddToLogFile($"From {FromPath} To {ToPath}", $"Copied Directory {Name}", "Success"); Global.Attention.AddContent(MyFunc.Set(2, 1), $"Successfully Copied Directory From {SourcePath} To {ToPath}"); } catch (UnauthorizedAccessException) { Global.Attention.AddContent(MyFunc.Set(2, 1), "Access Denied"); Global.AddToLogFile(SourcePath, "Trying to Copy Directory", "Access Denied"); } catch (Exception) { Global.Attention.AddContent(MyFunc.Set(2, 1), "Can not Copy Directory"); Global.AddToLogFile(SourcePath, "Trying to Copy Directory", "Can not Copy Directory"); } return; } }
void DeleteUnit(string CurrentFullName, Global.Types CurrentType) { if (CurrentType == Global.Types.File) { try { File.Delete(CurrentFullName); Global.AddToLogFile(CurrentFullName, "Deleted File", "Success"); Global.Attention.AddContent(MyFunc.Set(2, 1), $"Successfully Deleted File {CurrentFullName}"); } catch (UnauthorizedAccessException) { Global.Attention.AddContent(MyFunc.Set(2, 1), "Access Denied"); Global.AddToLogFile(CurrentFullName, "Trying to Delete File", "Access Denied"); } catch (Exception) { Global.Attention.AddContent(MyFunc.Set(2, 1), "Can not Delete File"); Global.AddToLogFile(CurrentFullName, "Trying to make Delete File", "Can not make Delete File"); } return; } if (CurrentType == Global.Types.Directory) { try { Directory.Delete(CurrentFullName, true); Global.AddToLogFile(CurrentFullName, "Deleted Directory", "Success"); Global.Attention.AddContent(MyFunc.Set(2, 1), $"Successfully Deleted Directory {CurrentFullName}"); } catch (UnauthorizedAccessException) { Global.Attention.AddContent(MyFunc.Set(2, 1), "Access Denied"); Global.AddToLogFile(CurrentFullName, "Trying to Delete Directory", "Access Denied"); } catch (Exception) { Global.Attention.AddContent(MyFunc.Set(2, 1), "Can not Delete Directory"); Global.AddToLogFile(CurrentFullName, "Trying to make Delete Directory", "Can not make Delete Directory"); } return; } }