Skip to content

Commit

Permalink
Copy folder to multiple folders (initial checkin) + build config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Finkelshteyn committed Jan 12, 2019
1 parent a533ca4 commit e36b2d9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 19 deletions.
2 changes: 1 addition & 1 deletion UBCopy/AsyncUnbuffCopyStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private static void AsyncWriteFile()
if ((percent - currentPercent) >= 1)
{
currentPercent = percent;
Console.Write("\r{0}%", currentPercent);
Console.Write("\r{0}% ({1})", currentPercent, _outputfile);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion UBCopy/UBCopy.csproj.user
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<StartArguments>-s="C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Windows81.vhdx" -d="C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Windows81---copy.vhdx" -o=true -b=8 -c=false -m=false -t=8 -z=32 -l=31457280 -r=true</StartArguments>
<StartArguments>-s="C:\Temp\Deleteme\UBCopyTest" -d="C:\Temp\Deleteme\UBCopyTest2%3bC:\Temp\Deleteme\UBCopyTest3%3bC:\Temp\Deleteme\UBCopyTest4" -o=false -b=8 -c=false -m=false -t=8 -z=32 -l=31457280 -r=true</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<StartArguments>-s=k:\downloads\SQL2000-KB884525-SP4-x86-ENU.EXE -d=c:\delme.zip -o=true -c=false -r=true -b=1</StartArguments>
Expand Down
14 changes: 9 additions & 5 deletions UBCopy/UBCopyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static int ProcessFiles(string inputfile, string outputfile, bool overwri
throw new Exception("Target cannot be empty");

var inputIsFile = false;
UBCopySetup.Overwritedestination = overwrite;
UBCopySetup.Buffersize = buffersize;
UBCopySetup.Checksumfiles = checksum;
UBCopySetup.Destinationfile = outputfile;
Expand Down Expand Up @@ -116,16 +117,16 @@ public static int ProcessFiles(string inputfile, string outputfile, bool overwri

if (UBCopySetup.FileList.Count < numberthreads)
{
numberthreads = UBCopySetup.FileList.Count;
numberthreads = UBCopySetup.FileToFolderList.Count;
}

if (inputIsFile)
numberthreads = 1;

Log.InfoFormat("Number of Files To Process: {0}", UBCopySetup.FileList.Count);
Console.WriteLine("Number of file to folder combinatins: {0}", UBCopySetup.FileToFolderList.Count);
var sw = new Stopwatch();
sw.Start();
var ftph = UBCopySetup.FileList.Count;
var ftph = UBCopySetup.FileToFolderList.Count;

if (numberthreads == 1)
{
Expand Down Expand Up @@ -153,14 +154,17 @@ public static int ProcessFiles(string inputfile, string outputfile, bool overwri
{
var doneEvents = new ManualResetEvent[numberthreads];
var hashFilesArray = new UBCopyProcessor[numberthreads];
var ftp = UBCopySetup.FileList.Count;
var ftp = UBCopySetup.FileToFolderList.Count;


while (ftp > 0)
{
// Configure and launch threads using ThreadPool:
if (ftp < numberthreads)
numberthreads = ftp;

Console.WriteLine("Number of threads: " + numberthreads);

for (var i = 0; i < numberthreads; i++)
{
doneEvents[i] = new ManualResetEvent(false);
Expand All @@ -171,7 +175,7 @@ public static int ProcessFiles(string inputfile, string outputfile, bool overwri

// Wait for all threads in pool to finished processing
WaitHandle.WaitAll(doneEvents);
ftp = UBCopySetup.FileList.Count;
ftp = UBCopySetup.FileToFolderList.Count;
}
}
sw.Stop();
Expand Down
6 changes: 3 additions & 3 deletions UBCopy/UBCopyMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ private static int Main(string[] args)
}

sw.Stop();
Log.InfoFormat("Number of Byes Copied : {0}", UBCopySetup.BytesCopied);
Log.InfoFormat("Elapsed Seconds : {0}", sw.ElapsedMilliseconds / 1000.00);
Log.Info("Done.");
Console.WriteLine ("Number of Bytes Copied : {0}", UBCopySetup.BytesCopied);
Console.WriteLine("Elapsed Seconds : {0}", sw.ElapsedMilliseconds / 1000.00);
Console.WriteLine("Done.");
#if DEBUG
{
Console.ReadKey();
Expand Down
22 changes: 13 additions & 9 deletions UBCopy/UBCopyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ public void UBCopyThreadPoolCallback(Object threadContext)
/// </summary>
private static void UBCopyFile()
{
string file;

FileToFolder fileToFolder;

lock (UBCopySetup.DictonaryLocker)
{
file = UBCopySetup.FileList.Pop();
Log.DebugFormat("POP FILE: {0}", file);

fileToFolder = UBCopySetup.FileToFolderList.Pop();
Log.DebugFormat("POP FILE: {0} TO FOLDER {1}", fileToFolder.SourceFile, fileToFolder.DestinationFolder);
}
if (String.IsNullOrEmpty(file))
if (fileToFolder == null)
{
throw new Exception("File Name Cannot Be Null");
}
var destinationfile = Path.Combine(UBCopySetup.Destinationfile, file.Replace(Path.GetPathRoot(file), ""));
var fileSize = new FileInfo(file);
//var destinationfile = Path.Combine(UBCopySetup.Destinationfile, file.Replace(Path.GetPathRoot(file), ""));
var destinationfile = Path.Combine(fileToFolder.DestinationFolder, Path.GetFileName(fileToFolder.SourceFile));
var fileSize = new FileInfo(fileToFolder.SourceFile);

Log.DebugFormat("File Size: {0}", fileSize.Length);
lock (Locker)
Expand All @@ -57,18 +61,18 @@ private static void UBCopyFile()
if (fileSize.Length < UBCopySetup.SynchronousFileCopySize)
{
var asyncUnbufferedCopy = new AsyncUnbuffCopy();
asyncUnbufferedCopy.AsyncCopyFileUnbuffered(file, destinationfile, UBCopySetup.Overwritedestination,
asyncUnbufferedCopy.AsyncCopyFileUnbuffered(fileToFolder.SourceFile, destinationfile, UBCopySetup.Overwritedestination,
UBCopySetup.Movefile,
UBCopySetup.Checksumfiles, UBCopySetup.Buffersize,
UBCopySetup.Reportprogres,UBCopySetup.BytesSecond);
}
else
{
AsyncUnbuffCopyStatic.AsyncCopyFileUnbuffered(file, destinationfile, UBCopySetup.Overwritedestination,
AsyncUnbuffCopyStatic.AsyncCopyFileUnbuffered(fileToFolder.SourceFile, destinationfile, UBCopySetup.Overwritedestination,
UBCopySetup.Movefile,
UBCopySetup.Checksumfiles, UBCopySetup.Buffersize,
UBCopySetup.Reportprogres, UBCopySetup.BytesSecond);
}
}
}
}
}
23 changes: 23 additions & 0 deletions UBCopy/UBCopySetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static class UBCopySetup

public static Stack<string> FileList = new Stack<string>(50000);

public static Stack<FileToFolder> FileToFolderList = new Stack<FileToFolder>(50000);

//hold command line options
//public static string Sourcefile;
public static string Destinationfile;
Expand All @@ -62,6 +64,9 @@ public static class UBCopySetup
/// <param name="root"></param>
public static void TraverseTree(string root)
{
string[] destinationFolderList = Destinationfile.Contains(",") || Destinationfile.Contains(";") ? Destinationfile.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
: new string[] { Destinationfile };

var dirs = new Stack<string>(20);

if (!Directory.Exists(root))
Expand Down Expand Up @@ -116,6 +121,12 @@ public static void TraverseTree(string root)
try
{
FileList.Push(file);

foreach (var folder in destinationFolderList)
{
FileToFolderList.Push(new FileToFolder(file, folder));
}

}
catch (FileNotFoundException)
{
Expand All @@ -131,4 +142,16 @@ public static void TraverseTree(string root)
}
}
}

public class FileToFolder
{
public string SourceFile { get; set; }
public string DestinationFolder { get; set; }

public FileToFolder(string sourceFile, string destinationFolder)
{
SourceFile = sourceFile;
DestinationFolder = destinationFolder;
}
}
}
14 changes: 14 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 1.0.{build}
skip_tags: true
configuration: Release
build:
verbosity: minimal
artifacts:
- path: UBCopy\bin\$(configuration)
name: UBCopy
deploy:
- provider: GitHub
auth_token:
secure: KmYWY9jz5FpXpKkxpQvthnDkZiMCi0tmh5PCs/83mu4vm0QsEThuEqhEgMViCbCJ
on:
branch: internal-usage

0 comments on commit e36b2d9

Please sign in to comment.