Skip to content

Commit 50f2fb9

Browse files
committed
Code clean (regions) and fixed issues
Number of parts not recalculated #19 Need destination folder selector #18
1 parent 5046c61 commit 50f2fb9

File tree

3 files changed

+120
-18
lines changed

3 files changed

+120
-18
lines changed

FileSplitter/FrmSplitter.resx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,57 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<metadata name="lbFile.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
121+
<value>True</value>
122+
</metadata>
123+
<metadata name="txtFile.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
124+
<value>True</value>
125+
</metadata>
126+
<metadata name="cmdSelectFile.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
127+
<value>True</value>
128+
</metadata>
129+
<metadata name="grpSplitSize.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
130+
<value>True</value>
131+
</metadata>
132+
<metadata name="lbEstimatedParts.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
133+
<value>True</value>
134+
</metadata>
135+
<metadata name="cmbUnits.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
136+
<value>True</value>
137+
</metadata>
138+
<metadata name="numSize.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
139+
<value>True</value>
140+
</metadata>
141+
<metadata name="cmdStart.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
142+
<value>True</value>
143+
</metadata>
120144
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121145
<value>17, 17</value>
122146
</metadata>
147+
<metadata name="panelSpitting.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
148+
<value>True</value>
149+
</metadata>
150+
<metadata name="lbCurrentFileProgress.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
151+
<value>True</value>
152+
</metadata>
153+
<metadata name="lbAllFilesProgress.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
154+
<value>True</value>
155+
</metadata>
156+
<metadata name="progressBarFileSize.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
157+
<value>True</value>
158+
</metadata>
159+
<metadata name="progressBarFiles.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
160+
<value>True</value>
161+
</metadata>
162+
<metadata name="lbSplitInfo.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
163+
<value>True</value>
164+
</metadata>
165+
<metadata name="lbInfo.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
166+
<value>True</value>
167+
</metadata>
168+
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
169+
<value>True</value>
170+
</metadata>
123171
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
124172
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
125173
<value>

FileSplitter/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static void Main(String[] args) {
146146
// Check destination Folder
147147
destinationFolder = extractKeyWhenSet(CommandLine.DestinationFolderParameterCmd, "Invalid destination");
148148

149+
149150
// Check file to save names
150151
outLogFile = extractKeyWhenSet(CommandLine.LogFileParameterCmd, "Invalid file");
151152

FileSplitter/Splitter/FileSplitWorker.cs

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace FileSplitter {
3030
/// </remarks>
3131
public class FileSplitWorker {
3232

33+
#region Buffer and size constants
34+
3335
/// <summary>
3436
/// Default buffer size
3537
/// </summary>
@@ -55,6 +57,8 @@ public class FileSplitWorker {
5557
/// </summary>
5658
static readonly Int32 MINIMUM_PART_SIZE = BUFFER_SIZE;
5759

60+
#endregion
61+
5862
#region File System related limits
5963

6064
const string DriveFormat_FAT12 = "FAT12";
@@ -71,7 +75,9 @@ public class FileSplitWorker {
7175
const string DriveFormat_FAT32_FactorName = "Gb";
7276

7377
#endregion
74-
78+
79+
#region Delegates and events
80+
7581
/// <summary>
7682
/// Delegate for Split start
7783
/// </summary>
@@ -116,10 +122,44 @@ public class FileSplitWorker {
116122
/// </summary>
117123
public event MessageHandler message;
118124

125+
#endregion
126+
127+
#region Private variables
128+
129+
/// <summary>
130+
/// Stores the numbers of partes calculated if the partSize o unit is not changed
131+
/// to reduce the number of recalculations
132+
/// </summary>
133+
private Int32 partsCache;
134+
135+
/// <summary>
136+
/// Size of the part (depending on the part unit)
137+
/// </summary>
138+
private Int64 partSize;
139+
140+
/// <summary>
141+
/// Operation mode to use
142+
/// </summary>
143+
private SplitUnit operationMode;
144+
145+
#endregion
146+
147+
#region Properties
148+
119149
/// <summary>
120150
/// Getter for the part size in bytes
121151
/// </summary>
122-
public Int64 PartSize { get; set; }
152+
public Int64 PartSize {
153+
get {
154+
return partSize;
155+
}
156+
set {
157+
if (value != partSize) {
158+
partsCache = 0;
159+
partSize = value;
160+
}
161+
}
162+
}
123163

124164
/// <summary>
125165
/// Filename to be split
@@ -129,9 +169,17 @@ public class FileSplitWorker {
129169
/// <summary>
130170
/// Operation Mode
131171
/// </summary>
132-
public SplitUnit OperationMode { get; set; }
133-
134-
private Int32 partsCache;
172+
public SplitUnit OperationMode {
173+
get {
174+
return operationMode;
175+
}
176+
set {
177+
if (value != operationMode) {
178+
partsCache = 0;
179+
operationMode = value;
180+
}
181+
}
182+
}
135183

136184
/// <summary>
137185
/// Calculates number of parts, based on size of file a part size
@@ -184,15 +232,9 @@ public Int32 Parts {
184232
/// </summary>
185233
public String GenerationLogFile { get; set; }
186234

187-
/// <summary>
188-
/// Adds the file name to the log file
189-
/// </summary>
190-
/// <param name="fileName"></param>
191-
private void registerCreatedFile(String fileName) {
192-
if (GenerationLogFile != null) {
193-
File.AppendAllText(GenerationLogFile, fileName + Environment.NewLine);
194-
}
195-
}
235+
#endregion
236+
237+
#region event helper functions
196238

197239
/// <summary>
198240
/// Launch splitStart event
@@ -236,6 +278,17 @@ private void onMessage(ExceptionMessage msg, params Object[] parameters) {
236278
message(this, new MessageArgs(msg, parameters));
237279
}
238280
}
281+
#endregion
282+
283+
/// <summary>
284+
/// Adds the file name to the log file
285+
/// </summary>
286+
/// <param name="fileName"></param>
287+
private void registerCreatedFile(String fileName) {
288+
if (GenerationLogFile != null) {
289+
File.AppendAllText(GenerationLogFile, fileName + Environment.NewLine);
290+
}
291+
}
239292

240293
/// <summary>
241294
/// Generates and registers next file name in the correct destination folder
@@ -268,7 +321,6 @@ private Int64 getNumberOfLines(String inputFileName) {
268321
return linesReaded;
269322
}
270323

271-
272324
/// <summary>
273325
/// Split file by number of lines
274326
/// </summary>
@@ -277,7 +329,6 @@ private Int64 getNumberOfLines(String inputFileName) {
277329
/// <param name="sourceFileSize"></param>
278330
private void splitByLines(String inputFileName, Int64 sourceFileSize) {
279331

280-
281332
// File Pattern
282333
Int64 actualFileNumber = 1;
283334
String actualFileName = getNextFileName(actualFileNumber);
@@ -418,7 +469,6 @@ private void splitBySize(String inputFileName, Int64 sourceFileSize) {
418469
}
419470
}
420471

421-
422472
/// <summary>
423473
/// Do split operation
424474
/// </summary>
@@ -476,6 +526,9 @@ public void doSplit() {
476526
if (!di.Exists) {
477527
di.Create();
478528
}
529+
} else {
530+
//If destination not set use original file path
531+
DestinationFolder = Path.GetDirectoryName(this.FileName);
479532
}
480533

481534
if (OperationMode != SplitUnit.Lines) {
@@ -496,4 +549,4 @@ public void doSplit() {
496549
}
497550
}
498551
}
499-
}
552+
}

0 commit comments

Comments
 (0)