Skip to content

Commit

Permalink
Added preliminary write perm check
Browse files Browse the repository at this point in the history
Switched to TLS1.2 for Updater
Fixed MoveDialog not closing after Abort
  • Loading branch information
imDema committed Jun 7, 2018
1 parent 7223f47 commit cf1d3fe
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 79 deletions.
59 changes: 38 additions & 21 deletions FreeMove/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

157 changes: 109 additions & 48 deletions FreeMove/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private async void Form1_Load(object sender, EventArgs e)
SetToolTips();

//Check whether the program is set to update on its start
if (Settings.AutoUpdate())
if (Settings.AutoUpdate)
{
//Update the menu item accordingly
checkOnProgramStartToolStripMenuItem.Checked = true;
Expand All @@ -37,6 +37,10 @@ private async void Form1_Load(object sender, EventArgs e)
//If there is an update show the update dialog
if (updater != null) updater.ShowDialog();
}
if(Settings.PermCheck)
{
PermissionCheckToolStripMenuItem.Checked = true;
}
}

#endregion
Expand Down Expand Up @@ -105,7 +109,7 @@ private bool CheckFolders(string source, string destination)
errors += "ERROR, destination folder already contains a folder with the same name\n\n";
passing = false;
}
if (!Directory.Exists(Directory.GetParent(destination).FullName))
if (passing && !Directory.Exists(Directory.GetParent(destination).FullName))
{
errors += "destination folder doesn't exist\n\n";
passing = false;
Expand Down Expand Up @@ -141,6 +145,42 @@ private bool CheckFolders(string source, string destination)
}
if (Directory.Exists(TestFile))
Directory.Delete(TestFile);

//If set to do full check try to open for write all files
if(passing && Settings.PermCheck)
{
Parallel.ForEach(Directory.GetFiles(source), file =>
{
CheckFile(file);
});
Parallel.ForEach(Directory.GetDirectories(source), dir =>
{
Parallel.ForEach(Directory.GetFiles(dir), file =>
{
CheckFile(file);
});
});

void CheckFile(string file)
{
FileInfo fi = new FileInfo(file);
FileStream fs = null;
try
{
fs = fi.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException ex)
{
passing = false;
errors += $"{ex.Message}\n";
}
finally
{
if (fs != null)
fs.Dispose();
}
}
}
}

//Check if there's enough free space on disk
Expand All @@ -162,55 +202,12 @@ private bool CheckFolders(string source, string destination)


if (!passing)
MessageBox.Show(errors);
MessageBox.Show(errors, "Errors encounered during preliminary phase");

return passing;
}

private bool StartMoving(string source, string destination, bool doNotReplace, string ProgressMessage)
{
return _StartMoving(new MoveDialog(source, destination, doNotReplace, ProgressMessage));
}
private bool StartMoving(string source, string destination, bool doNotReplace)
{
return _StartMoving(new MoveDialog(source, destination, doNotReplace));
}
private bool _StartMoving(MoveDialog mvDiag)
{
mvDiag.ShowDialog();
return mvDiag.Result;
}

//Configure tooltips
private void SetToolTips()
{
ToolTip Tip = new ToolTip()
{
ShowAlways = true,
AutoPopDelay = 5000,
InitialDelay = 600,
ReshowDelay = 500
};
Tip.SetToolTip(this.textBox_From, "Select the folder you want to move");
Tip.SetToolTip(this.textBox_To, "Select where you want to move the folder");
Tip.SetToolTip(this.checkBox1, "Select whether you want to hide the shortcut which is created in the old location or not");
}

private void Reset()
{
textBox_From.Text = "";
textBox_To.Text = "";
textBox_From.Focus();
}

public static void Unauthorized(Exception ex)
{
MessageBox.Show(Properties.Resources.ErrorUnauthorizedMoveDetails + ex.Message, "Error details");
}
#endregion

#region Event Handlers
private void Button_Move_Click(object sender, EventArgs e)
private void Begin()
{
//Get the original and the new path from the textboxes
string source, destination;
Expand Down Expand Up @@ -276,6 +273,55 @@ private void Button_Move_Click(object sender, EventArgs e)
}
}
}

}

private bool StartMoving(string source, string destination, bool doNotReplace, string ProgressMessage)
{
return _StartMoving(new MoveDialog(source, destination, doNotReplace, ProgressMessage));
}
private bool StartMoving(string source, string destination, bool doNotReplace)
{
return _StartMoving(new MoveDialog(source, destination, doNotReplace));
}
private bool _StartMoving(MoveDialog mvDiag)
{
mvDiag.ShowDialog();
return mvDiag.Result;
}

//Configure tooltips
private void SetToolTips()
{
ToolTip Tip = new ToolTip()
{
ShowAlways = true,
AutoPopDelay = 5000,
InitialDelay = 600,
ReshowDelay = 500
};
Tip.SetToolTip(this.textBox_From, "Select the folder you want to move");
Tip.SetToolTip(this.textBox_To, "Select where you want to move the folder");
Tip.SetToolTip(this.checkBox1, "Select whether you want to hide the shortcut which is created in the old location or not");
}

private void Reset()
{
textBox_From.Text = "";
textBox_To.Text = "";
textBox_From.Focus();
}

public static void Unauthorized(Exception ex)
{
MessageBox.Show(Properties.Resources.ErrorUnauthorizedMoveDetails + ex.Message, "Error details");
}
#endregion

#region Event Handlers
private void Button_Move_Click(object sender, EventArgs e)
{
Begin();
}

//Show a directory picker for the source directory
Expand All @@ -298,6 +344,15 @@ private void Button_BrowseTo_Click(object sender, EventArgs e)
}
}

//Start on enter key press
private void TextBox_To_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
Begin();
}
}

//Close the form
private void Button_Close_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -326,13 +381,19 @@ private void CheckNowToolStripMenuItem_Click(object sender, EventArgs e)
private void CheckOnProgramStartToolStripMenuItem_Click(object sender, EventArgs e)
{
Settings.ToggleAutoUpdate();
checkOnProgramStartToolStripMenuItem.Checked = Settings.AutoUpdate();
checkOnProgramStartToolStripMenuItem.Checked = Settings.AutoUpdate;
}
#endregion

private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("ImDema/FreeMove\n\nFreeMove is licensed under the GNU General Public License v3.0\nFor more informations https://github.com/imDema/FreeMove/blob/master/LICENSE.txt \n\nhttps://github.com/imDema", "About FreeMove");
}

private void FullPermissionCheckToolStripMenuItem_Click(object sender, EventArgs e)
{
Settings.TogglePermCheck();
PermissionCheckToolStripMenuItem.Checked = Settings.PermCheck;
}
}
}
2 changes: 1 addition & 1 deletion FreeMove/ProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected async override void OnShown(EventArgs e)
base.OnShown(e);
Result = await Task.Run(() => MoveFolder(Source, Destination, DoNotReplace));
Close();
Dispose();
}

private bool MoveFolder(string source, string destination, bool doNotReplace)
Expand Down Expand Up @@ -68,7 +69,6 @@ private bool MoveFolder(string source, string destination, bool doNotReplace)
case DialogResult.Abort:
MoveFolder(destination, source, true, "Moving the files back, please wait...");
Invoke(new Action (() => MessageBox.Show("The contents of the directory were moved back to their original position.")));
Form1.Unauthorized(ex);
return false;

case DialogResult.Retry:
Expand Down
6 changes: 3 additions & 3 deletions FreeMove/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("imDema")]
[assembly: AssemblyProduct("FreeMove")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -33,5 +33,5 @@
// usando l'asterisco '*' come illustrato di seguito:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyVersion("1.5.0")]
[assembly: AssemblyFileVersion("1.5.0")]
Loading

0 comments on commit cf1d3fe

Please sign in to comment.