Skip to content

Commit

Permalink
Merge pull request #462 from TV-Rename/code-tidy
Browse files Browse the repository at this point in the history
Code tidy
  • Loading branch information
SirSparkles authored Aug 6, 2018
2 parents f32345b + 5a88d47 commit 6d31e0e
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 143 deletions.
1 change: 0 additions & 1 deletion TVRename/Forms/AddEditShow.Designer.cs

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

33 changes: 17 additions & 16 deletions TVRename/Forms/AddEditShow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,17 @@ private void SetShow()

private void bnBrowse_Click(object sender, EventArgs e)
{
searchFolderBrowser.Title = "Add Folder...";
searchFolderBrowser.ShowEditbox = true;
searchFolderBrowser.ShowNewFolderButton = true;
searchFolderBrowser.StartPosition = FormStartPosition.CenterScreen;
//folderBrowser.Title = "Add Folder...";
//folderBrowser.ShowEditbox = true;
//folderBrowser.StartPosition = FormStartPosition.CenterParent;

folderBrowser.ShowNewFolderButton = true;

if (!string.IsNullOrEmpty(txtBaseFolder.Text))
searchFolderBrowser.SelectedPath = txtBaseFolder.Text;
folderBrowser.SelectedPath = txtBaseFolder.Text;

if (searchFolderBrowser.ShowDialog(this) == DialogResult.OK)
txtBaseFolder.Text = searchFolderBrowser.SelectedPath;
if (folderBrowser.ShowDialog(this) == DialogResult.OK)
txtBaseFolder.Text = folderBrowser.SelectedPath;
}

private void cbDoMissingCheck_CheckedChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -281,19 +282,19 @@ private void bnAdd_Click(object sender, EventArgs e)

private void bnBrowseFolder_Click(object sender, EventArgs e)
{
searchFolderBrowser.Title = "Add Folder...";
searchFolderBrowser.ShowEditbox = true;
searchFolderBrowser.ShowNewFolderButton = true;
searchFolderBrowser.StartPosition = FormStartPosition.CenterScreen;
//folderBrowser.Title = "Add Folder...";
//folderBrowser.ShowEditbox = true;
//folderBrowser.StartPosition = FormStartPosition.CenterParent;
folderBrowser.ShowNewFolderButton = true;

if (!string.IsNullOrEmpty(txtFolder.Text))
searchFolderBrowser.SelectedPath = txtFolder.Text;
folderBrowser.SelectedPath = txtFolder.Text;

if(string.IsNullOrWhiteSpace(searchFolderBrowser.SelectedPath) && !string.IsNullOrWhiteSpace(txtBaseFolder.Text))
searchFolderBrowser.SelectedPath = txtBaseFolder.Text;
if(string.IsNullOrWhiteSpace(folderBrowser.SelectedPath) && !string.IsNullOrWhiteSpace(txtBaseFolder.Text))
folderBrowser.SelectedPath = txtBaseFolder.Text;

if (searchFolderBrowser.ShowDialog(this) == DialogResult.OK)
txtFolder.Text = searchFolderBrowser.SelectedPath;
if (folderBrowser.ShowDialog(this) == DialogResult.OK)
txtFolder.Text = folderBrowser.SelectedPath;
}

private void txtSeasonNumber_TextChanged(object sender, EventArgs e) => CheckToEnableAddButton();
Expand Down
9 changes: 6 additions & 3 deletions TVRename/Forms/FolderBrowserDialogEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ public DialogResult ShowDialog(IWin32Window owner)
{
InitData initdata = new InitData(this, owner.Handle);

Win32.BROWSEINFO bi = new Win32.BROWSEINFO();
bi.iImage = 0;
bi.hwndOwner = owner.Handle;
Win32.BROWSEINFO bi = new Win32.BROWSEINFO
{
iImage = 0,
hwndOwner = owner.Handle
};

if (0 != Win32.SHGetSpecialFolderLocation(owner.Handle, (int)RootFolder, ref bi.pidlRoot))
bi.pidlRoot = IntPtr.Zero;
bi.lpszTitle = "";
Expand Down
72 changes: 48 additions & 24 deletions TVRename/Forms/UI.Designer.cs

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

94 changes: 15 additions & 79 deletions TVRename/Forms/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ private void UI_Load(object sender, EventArgs e)
if (TVSettings.Instance.BGDownload)
BGDownloadTimer.Start();

UpdateTimer.Start();

quickTimer.Start();

if (TVSettings.Instance.RunOnStartUp())
Expand Down Expand Up @@ -1880,6 +1882,14 @@ private void backgroundDownloadToolStripMenuItem_Click(object sender, EventArgs
BGDownloadTimer.Stop();
}

private async void UpdateTimer_Tick(object sender, EventArgs e)
{
UpdateTimer.Stop();

Task<UpdateVersion> tuv = VersionUpdater.CheckForUpdatesAsync();
NotifyUpdates(await tuv, false);
}

private void BGDownloadTimer_Tick(object sender, EventArgs e)
{
if (busy != 0)
Expand Down Expand Up @@ -2298,80 +2308,6 @@ private void MyShowTree_AfterSelect(object sender, TreeViewEventArgs e)
bnMyShowsDelete.Enabled = showSelected;
}

private void bnMyShowsVisitTVDB_Click(object sender, EventArgs e)
{
TreeNode n = MyShowTree.SelectedNode;
ShowItem si = TreeNodeToShowItem(n);
if (si == null)
return;

Season seas = TreeNodeToSeason(n);

int sid = -1;
if (seas != null)
sid = seas.SeasonId;

Helpers.SysOpen(TheTVDB.Instance.WebsiteUrl(si.TvdbCode, sid, false));
}

private void bnMyShowsOpenFolder_Click(object sender, EventArgs e)
{
TreeNode n = MyShowTree.SelectedNode;
ShowItem si = TreeNodeToShowItem(n);
if (si == null)
return;

Season seas = TreeNodeToSeason(n);
Dictionary<int, List<string>> afl = si.AllFolderLocations();
int[] keys = new int[afl.Count];
afl.Keys.CopyTo(keys, 0);
if (seas == null && keys.Length > 0)
{
string f = si.AutoAddFolderBase;
if (string.IsNullOrEmpty(f))
{
int n2 = keys[0];
if (afl[n2].Count > 0)
f = afl[n2][0];
}

if (!string.IsNullOrEmpty(f))
{
try
{
Helpers.SysOpen(f);
return;
}
catch
{
// ignored
}
}
}

if (seas != null && afl.ContainsKey(seas.SeasonNumber))
{
foreach (string folder in afl[seas.SeasonNumber])
{
if (Directory.Exists(folder))
{
Helpers.SysOpen(folder);
return;
}
}
}

try
{
if (!string.IsNullOrEmpty(si.AutoAddFolderBase) && Directory.Exists(si.AutoAddFolderBase))
Helpers.SysOpen(si.AutoAddFolderBase);
}
catch
{
// ignored
}
}

private void MyShowTree_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right)
Expand Down Expand Up @@ -3508,11 +3444,11 @@ private async void checkForNewVersionToolStripMenuItem_Click(object sender, Even
NotifyUpdates(await uv, true);
}

private static void NotifyUpdates(UpdateVersion update, bool showNoUpdateRequiredDialog, bool inSilentMode = false)
private void NotifyUpdates(UpdateVersion update, bool showNoUpdateRequiredDialog, bool inSilentMode = false)
{
if (update is null)
{
//this.btnUpdateAvailable.Visible = false;
this.btnUpdateAvailable.Visible = false;
if (showNoUpdateRequiredDialog && !inSilentMode)
{
MessageBox.Show(@"There is no update available please try again later.", @"No update available",
Expand All @@ -3527,7 +3463,7 @@ private static void NotifyUpdates(UpdateVersion update, bool showNoUpdateRequire

UpdateNotification unForm = new UpdateNotification(update);
unForm.ShowDialog();
//this.btnUpdateAvailable.Visible = true;
this.btnUpdateAvailable.Visible = true;
}

private void duplicateFinderLOGToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -3537,9 +3473,9 @@ private void duplicateFinderLOGToolStripMenuItem_Click(object sender, EventArgs
form.ShowDialog();
}

// ReSharper disable once UnusedMember.Local
private async void btnUpdateAvailable_Click()
private async void btnUpdateAvailable_Click(object sender, EventArgs e)
{
btnUpdateAvailable.Visible = false;
Task<UpdateVersion> uv = VersionUpdater.CheckForUpdatesAsync();
NotifyUpdates(await uv, true);
}
Expand Down
Loading

0 comments on commit 6d31e0e

Please sign in to comment.