Skip to content

Commit 13fe98b

Browse files
Merge pull request #16 from AngelsSoftwareOrg/develop
Cycle Release - OneClickZipSetup_v1.0.6_Release Bug Fix - When creating a batch file (one click shortcut), make sure the reference project file targets the designer file, not the batch file. Bug Fix - Improve the validation of duplicate folder on target Location form Bug Fix - When archiving, if a file has been locked on or used by another process, then ignore it and log an event Enhance - If target locations doesnt exist, try to create it automatically Enhance - Improve showing up the target location form Enhance - Improve the handling of folder without a permission access. Enhance - When adding new Folder on target Location Form, automatic put the selected folder as default.
2 parents 562ece4 + c2b11f4 commit 13fe98b

File tree

15 files changed

+199
-65
lines changed

15 files changed

+199
-65
lines changed

.vs/OneClickZip/v16/.suo

-74 KB
Binary file not shown.

App.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<value>0</value>
1818
</setting>
1919
<setting name="app_version_patch" serializeAs="String">
20-
<value>5</value>
20+
<value>6</value>
2121
</setting>
2222
<setting name="app_version_revision" serializeAs="String">
2323
<value>r1</value>
@@ -56,7 +56,7 @@
5656
<value>angelsburger90</value>
5757
</setting>
5858
<setting name="github_access_token" serializeAs="String">
59-
<value>fba0a3bd40a064a</value>
59+
<value>xxx_fba0a3bd40a064a_xxx</value>
6060
</setting>
6161
</OneClickZip.Properties.Settings>
6262
</applicationSettings>

Forms/Options/OneClickProcessorFrm.cs

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ private void CopyOutputToOtherTargetFolders(ZipArchivingEventArgs e)
114114
if (isStopProcessing) break;
115115
try
116116
{
117+
if (!IsDirectoryValidAndAccessible(targetOutputFolder))
118+
{
119+
AddLogItems("Copy file failed", String.Format(@"Failed to place the file [{1}] in [{0}] due to folder is not accessible" +
120+
@" or no read and write permission", targetOutputFolder, zipOutputFile.Name));
121+
continue;
122+
}
123+
117124
int bufferSize = 8 * 1024;
118125
using (FileStream sourceStream = new FileStream(zipOutputFullFilePathName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
119126
{
@@ -224,13 +231,24 @@ private void OpenProjectFileForZipping()
224231
serializedTreeNode = projectSession.GetSerializableTreeNodeBaseOnZipModel();
225232
}
226233
this.zipModel = projectSession.ZipFileModel;
227-
String newArchiveName = zipModel.GetFullPathFileAndNameOfNewZipArchive;
228-
this.Text = this.Text + " => " + Path.GetFileName(newArchiveName);
229-
zipArchiving.NewArchiveName = newArchiveName;
230-
zipArchiving.SerializableTreeNode = serializedTreeNode;
231-
zipArchiving.ZipFileModelSource = zipModel;
232-
zipArchiving.CompressionLevelArchiving = CompressionLevel.BestCompression; ;
233-
zipArchiving.StartArchiving();
234+
if (IsDirectoryValidAndAccessible(this.zipModel.MainTargetLocationDirectory))
235+
{
236+
String newArchiveName = zipModel.GetFullPathFileAndNameOfNewZipArchive;
237+
this.Text = this.Text + " => " + Path.GetFileName(newArchiveName);
238+
zipArchiving.NewArchiveName = newArchiveName;
239+
zipArchiving.SerializableTreeNode = serializedTreeNode;
240+
zipArchiving.ZipFileModelSource = zipModel;
241+
zipArchiving.CompressionLevelArchiving = CompressionLevel.BestCompression;
242+
zipArchiving.StartArchiving();
243+
}
244+
else
245+
{
246+
MessageBox.Show(String.Format("The target location for archiving '{0}' is not accessible!",
247+
this.zipModel.MainTargetLocationDirectory),
248+
"Access Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
249+
isWindowCanBeClose = true;
250+
btnStop.Enabled = false;
251+
}
234252
}
235253
private void GetStatistic(ZipFileStatisticsModel statObj)
236254
{
@@ -284,24 +302,7 @@ private void copySelectedLogToolStripMenuItem_Click(object sender, EventArgs e)
284302
}
285303
private void linkSaveLogs_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
286304
{
287-
SaveFileDialog saveFileDialog = new SaveFileDialog();
288-
saveFileDialog.Filter = ResourcesUtil.GetFileLogFilterName();
289-
saveFileDialog.Title = "Save a log file";
290-
DialogResult dr = saveFileDialog.ShowDialog();
291-
292-
if(dr == DialogResult.OK)
293-
{
294-
using (StreamWriter file = new StreamWriter(saveFileDialog.FileName))
295-
{
296-
foreach(ListViewItem lvItem in listViewLogs.Items)
297-
{
298-
file.WriteLine(lvItem.SubItems[0].Text + "\t" +
299-
lvItem.SubItems[1].Text + "\t" +
300-
lvItem.SubItems[2].Text + "\t");
301-
}
302-
}
303-
MessageBox.Show("Log file has been successfully save...", "File saving...");
304-
}
305+
FileSystemUtilities.SaveListViewItemsToLogFile(listViewLogs);
305306
}
306307
private void OneClickProcessor_FormClosed(object sender, FormClosedEventArgs e)
307308
{
@@ -319,5 +320,15 @@ private void BeforeClosingForm()
319320
}
320321
this.DialogResult = DialogResult.OK;
321322
}
323+
private bool IsDirectoryValidAndAccessible(String dirPath)
324+
{
325+
if (!FileSystemUtilities.IsDirectoryExistInTheSystem(dirPath))
326+
{
327+
if (!FileSystemUtilities.MakeDirectory(dirPath)) return false;
328+
}
329+
if (!FileSystemUtilities.IsDirectoryHasReadAndWritePermission(dirPath)) return false;
330+
return true;
331+
}
332+
322333
}
323334
}

Forms/Options/TargetLocationsFrm.cs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Drawing;
34
using System.Windows.Forms;
45
using ExpTreeLib;
@@ -33,6 +34,7 @@ private void SetUpDefault()
3334
if (targetOutputLocationModel != null)
3435
{
3536
txtTargetLocationMain.Text = targetOutputLocationModel.MainTargetLocation;
37+
tableLayoutPanelSetLocations.Controls.Clear();
3638
foreach (String str in targetOutputLocationModel.GetTargetLocations())
3739
{
3840
AddNewTargetLocationControls(str);
@@ -46,7 +48,9 @@ private void btnCancel_Click(object sender, EventArgs e)
4648
}
4749
private void btnAddOtherFolder_Click(object sender, EventArgs e)
4850
{
49-
AddNewTargetLocationControls();
51+
AddNewTargetLocationControls(
52+
(FileSystemUtilities.IsDirectoryExistInTheSystem(SelectedPath)
53+
? SelectedPath : ""));
5054
}
5155
private void AddNewTargetLocationControls(String targetLocation="")
5256
{
@@ -109,21 +113,29 @@ private void AddNewTargetLocationControls(String targetLocation="")
109113
}
110114
private void BtnAddFolder_Click(object sender, EventArgs e)
111115
{
112-
if(!FileSystemUtilities.IsDirectoryExistInTheSystem(SelectedPath)) return;
116+
if (!FileSystemUtilities.IsDirectoryExistInTheSystem(SelectedPath)) return;
113117

114118
Button genericButton = (Button)sender;
115119
Panel panelContainer = (Panel)genericButton.Parent;
116120
TextBox addOtherLocation = AddedLocationTextBoxControl(panelContainer);
117-
if(IsUniqueTargetFolder(addOtherLocation, SelectedPath))
121+
if (!IsUniqueTargetLocation(addOtherLocation))
118122
{
119-
addOtherLocation.Text = SelectedPath;
120-
ColorControlBaseOnValidation(addOtherLocation, true);
123+
MessageBox.Show("Duplicate target folder found. Please choose a unique folder...", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
124+
}
125+
}
126+
private bool IsUniqueTargetLocation(TextBox sourceLocation)
127+
{
128+
if (IsUniqueTargetFolder(sourceLocation, SelectedPath))
129+
{
130+
sourceLocation.Text = SelectedPath;
131+
ColorControlBaseOnValidation(sourceLocation, true);
132+
return true;
121133
}
122134
else
123135
{
124-
MessageBox.Show("Duplicate target folder found. Please choose a unique folder...", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
125-
ColorControlBaseOnValidation(addOtherLocation, false);
126-
}
136+
ColorControlBaseOnValidation(sourceLocation, false);
137+
}
138+
return false;
127139
}
128140
private void LinkLabelRemove_Click(object sender, EventArgs e)
129141
{
@@ -195,11 +207,23 @@ private bool AreTargetLocationsValid()
195207
int invalidFormCtr = 0;
196208
if (!IsTextboxValueValid(txtTargetLocationMain)) invalidFormCtr++;
197209

210+
List<String> targets = new List<string>();
211+
targets.Add(txtTargetLocationMain.Text);
212+
198213
//Other Controls
199-
foreach(Control control in tableLayoutPanelSetLocations.Controls)
214+
foreach (Control control in tableLayoutPanelSetLocations.Controls)
200215
{
201216
TextBox txtBoxControl = AddedLocationTextBoxControl((Panel)control);
202217
if (!IsTextboxValueValid(txtBoxControl)) invalidFormCtr++;
218+
if (targets.Contains(txtBoxControl.Text))
219+
{
220+
invalidFormCtr++;
221+
_ = IsUniqueTargetLocation(txtBoxControl);
222+
}
223+
else
224+
{
225+
targets.Add(txtBoxControl.Text);
226+
}
203227
}
204228

205229
return (invalidFormCtr<=0);
@@ -239,6 +263,10 @@ public TargetOutputLocationModel TargetOutputLocationModel
239263
{
240264
return targetOutputLocationModel;
241265
}
266+
set
267+
{
268+
targetOutputLocationModel = (TargetOutputLocationModel) value.Clone();
269+
}
242270
}
243271
private void btnDefault_Click(object sender, EventArgs e)
244272
{

Forms/ZipDesigner/ZipDesignerFrm.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class ZipDesigner : Form
2727
private TreeNodeInterpreter treeNodeInterpreter = new TreeNodeInterpreter();
2828
private ListViewInterpretor listViewInterpretor = new ListViewInterpretor();
2929
private UpdatesFrm updatesFrm = new UpdatesFrm();
30-
30+
private TargetLocationsFrm targetLocationFrm = null;
3131
public ZipDesigner()
3232
{
3333
InitializeComponent();
@@ -658,7 +658,15 @@ private void ZipDesigner_Load(object sender, EventArgs e)
658658

659659
private void lnlSetTargetLocation_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
660660
{
661-
TargetLocationsFrm targetLocationFrm = new TargetLocationsFrm(TargetOutputLocationModelObj);
661+
if(targetLocationFrm == null)
662+
{
663+
targetLocationFrm = new TargetLocationsFrm(TargetOutputLocationModelObj);
664+
}
665+
else
666+
{
667+
targetLocationFrm.TargetOutputLocationModel = TargetOutputLocationModelObj;
668+
}
669+
662670
if(targetLocationFrm.ShowDialog() == DialogResult.OK)
663671
{
664672
TargetOutputLocationModelObj = targetLocationFrm.TargetOutputLocationModel;

Includes/Classes/ZipArchiving.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,31 @@ private void CompleteFolderFilterRuleCrawler(SerializableTreeNode serializableTr
118118
}
119119
private void StartCrawling()
120120
{
121-
using (ZipFile archiveFile = new ZipFile(NewArchiveName))
121+
try
122122
{
123-
archiveFile.AlternateEncodingUsage = ZipOption.AsNecessary;
124-
archiveFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
125-
126-
UpdateStatusAndRaiseEventProcessingStatus(ZipProcessingStages.ZIP_CREATION);
127-
CrawlTreeStructure(serializableTreeNode, archiveFile, null);
128-
UpdateStatusAndRaiseEventProcessingStatus(ZipProcessingStages.POST_PROCESSING);
129-
archiveFile.Save();
130-
if (StopProcessing && StopProcessingSuccessful)
131-
{
132-
StopProcessingRaiseEvent();
133-
}
134-
else
123+
using (ZipFile archiveFile = new ZipFile(NewArchiveName))
135124
{
136-
FinishedArchivingRaiseEvent();
125+
archiveFile.AlternateEncodingUsage = ZipOption.AsNecessary;
126+
archiveFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
127+
128+
UpdateStatusAndRaiseEventProcessingStatus(ZipProcessingStages.ZIP_CREATION);
129+
CrawlTreeStructure(serializableTreeNode, archiveFile, null);
130+
UpdateStatusAndRaiseEventProcessingStatus(ZipProcessingStages.POST_PROCESSING);
131+
archiveFile.Save();
132+
if (StopProcessing && StopProcessingSuccessful)
133+
{
134+
StopProcessingRaiseEvent();
135+
}
136+
else
137+
{
138+
FinishedArchivingRaiseEvent();
139+
}
137140
}
138141
}
142+
catch (Exception)
143+
{
144+
StopProcessingRaiseEvent();
145+
}
139146
}
140147
private bool AddFileIntoZipArchive(ZipFile archiveFile, CustomFileItem customFileItem, String zipFileFolderName)
141148
{
@@ -145,21 +152,20 @@ private bool AddFileIntoZipArchive(ZipFile archiveFile, CustomFileItem customFil
145152

146153
String customFileName = (zipFileFolderName +
147154
FileSystemUtilities.SanitizeFileName(customFileItem.GetCustomFileName));
148-
149-
archiveFile.AddEntry(customFileName, File.OpenRead(customFileItem.FilePathFull));
150155
try
151156
{
157+
archiveFile.AddEntry(customFileName, File.OpenRead(customFileItem.FilePathFull));
158+
152159
//if there's a difference of, e.g. 50MB processed file size, then flush
153-
if((processedZipFileSize - processedFilesSizeFlusherCtr) >= processedFilesSizeFlusherThreshold)
160+
if ((processedZipFileSize - processedFilesSizeFlusherCtr) >= processedFilesSizeFlusherThreshold)
154161
{
155162
processedFilesSizeFlusherCtr = processedZipFileSize;
156163
archiveFile.Save();
157164
}
158165
}
159-
catch (Exception)
160-
{
161-
//just ignore if cannot accessed the file
162-
}
166+
//just ignore if cannot accessed the file
167+
catch (UnauthorizedAccessException) { return false; }
168+
catch (Exception) { return false; }
163169
return true;
164170
}
165171
private void CrawlTreeStructure(SerializableTreeNode serializableTreeNode, ZipFile archiveFile, String zipFileFolderName)

Includes/Models/ZipFileModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public String GetFullPathFileAndNameOfNewZipArchive
5959
{
6060
String targetPath = TargetOutputLocationModel.MainTargetLocation.Trim();
6161
if(!TargetOutputLocationModel.MainTargetLocation.EndsWith(@"\")) targetPath += @"\";
62-
return String.Format(@"{0}{1}.zip", targetPath, fileNameCreator.GetDerivedFormula());
62+
return (String.Format(@"{0}{1}.zip", targetPath, fileNameCreator.GetDerivedFormula()));
6363
}
6464
}
6565

@@ -102,5 +102,13 @@ public TargetOutputLocationModel TargetOutputLocationModel
102102
targetOutputLocationModel = value;
103103
}
104104
}
105+
106+
public String MainTargetLocationDirectory
107+
{
108+
get
109+
{
110+
return targetOutputLocationModel.MainTargetLocation;
111+
}
112+
}
105113
}
106114
}

0 commit comments

Comments
 (0)