private int CopyDirectory(ProgressPresenter caller, string sourceDirectory, string destinationDirectory, int copied = 0) { currentDirectory = new DirectoryInfo(sourceDirectory); subDirectories = currentDirectory.GetDirectories(); //Luodaan kansio, jos sitä ei ole olemassa if (!Directory.Exists(destinationDirectory)) { Directory.CreateDirectory(destinationDirectory); } CurrentOperation = "Current directoy: " + destinationDirectory; //Kopioidaan kansion tiedostot ja päivitetään edistyminen files = Directory.GetFiles(sourceDirectory); foreach (string file in files) { fileName = Path.GetFileName(file); CurrentOperation = "Copying file: " + fileName; //CopyFile ei kirjoita olemassa olevien tiedostojen yli, koska kolmas parametri true if (!CopyFile(Path.Combine(sourceDirectory, fileName), Path.Combine(destinationDirectory, fileName), true)) { CurrentOperation = "File skipped (already exists)"; } copied++; InstallCompletion = (int)(((float)copied / (float)filesToBeCopied) * 100.0f); } //Käydään rekursion avulla läpi kaikki alikansiot //Pidetään myös mukana kopioitujen tiedostojen lukumäärä, count foreach (DirectoryInfo directory in subDirectories) { copied = CopyDirectory(caller, directory.FullName, Path.Combine(destinationDirectory, directory.Name), copied); } return(copied); }
public void InstallFiles(ProgressPresenter caller) { CopyDirectory(caller, SourceDirectory, installDirectory); CurrentOperation = "Finished!"; }