Skip to content

Commit

Permalink
Fixed some exceptions and changed package managing
Browse files Browse the repository at this point in the history
- A bug was fixed that caused InvalidCastExceptions
- A bug was fixed that didn't delete packages correctly
- Specific actions with packages can now be performed, even if they
don't exist locally and they won't throw an error anymore.
  • Loading branch information
ProgTrade committed Apr 17, 2015
1 parent cd09567 commit e5c0a53
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 41 deletions.
17 changes: 9 additions & 8 deletions nUpdate.Administration/UI/Dialogs/ProjectDialog.Designer.cs

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

88 changes: 59 additions & 29 deletions nUpdate.Administration/UI/Dialogs/ProjectDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,6 @@ public void SetUiState(bool enabled)
// searchTextBox.Cue = ls.ProjectDialogSearchText;
//}

/// <summary>
/// Initializes the dialog with the data of the project.
/// </summary>
/// <returns>Returns whether the operation was successful or not.</returns>
private bool InitializeProjectData()
{
try
Expand Down Expand Up @@ -361,9 +357,6 @@ private bool InitializeProjectData()
return true;
}

/// <summary>
/// Adds the package items to the dialog's package listview.
/// </summary>
private void InitializePackageItems()
{
Invoke(new Action(() =>
Expand All @@ -380,23 +373,39 @@ private void InitializePackageItems()
try
{
var packageListViewItem = new ListViewItem(new UpdateVersion(package.Version).FullText);
var packageDirectoryInfo = new DirectoryInfo(package.LocalPackagePath);
var packageFileInfo = new FileInfo(package.LocalPackagePath);
if (packageFileInfo.Exists)
{
packageListViewItem.SubItems.Add(packageFileInfo.CreationTime.ToString());
var sizeInBytes = packageFileInfo.Length;
string sizeText = null;

if (sizeInBytes >= 107374182.4) // 0,1 GB
sizeText = String.Format("{0} GB", (float) Math.Round(sizeInBytes/GB, 1));
else if (sizeInBytes >= 104857.6) // 0,1 MB
sizeText = String.Format("{0} MB", (float) Math.Round(sizeInBytes/MB, 1));
else if (sizeInBytes >= 102.4) // 0,1 KB
sizeText = String.Format("{0} KB", (float) Math.Round(sizeInBytes/KB, 1));
else if (sizeInBytes >= 1) // 1 B
sizeText = String.Format("{0} B", sizeInBytes);

packageListViewItem.SubItems.Add(sizeText);
}
else
{
UpdatePackage package1 = package;
Invoke(new Action(() =>
{
Popup.ShowPopup(this, SystemIcons.Information, "Missing package file.",
String.Format(
"The package of version \"{0}\" could not be found on your computer. Specific actions and information won't be available.",
new UpdateVersion(package1.Version).FullText),
PopupButtons.Ok);
packageListViewItem.SubItems.Add("-");
packageListViewItem.SubItems.Add("-");
}));
}

packageListViewItem.SubItems.Add(packageDirectoryInfo.CreationTime.ToString());
var sizeInBytes = packageFileInfo.Length;
string sizeText = null;

if (sizeInBytes >= 107374182.4) // 0,1 GB
sizeText = String.Format("{0} GB", (float) Math.Round(sizeInBytes/GB, 1));
else if (sizeInBytes >= 104857.6) // 0,1 MB
sizeText = String.Format("{0} MB", (float) Math.Round(sizeInBytes/MB, 1));
else if (sizeInBytes >= 102.4) // 0,1 KB
sizeText = String.Format("{0} KB", (float) Math.Round(sizeInBytes/KB, 1));
else if (sizeInBytes >= 1) // 1 B
sizeText = String.Format("{0} B", sizeInBytes);

packageListViewItem.SubItems.Add(sizeText);
packageListViewItem.SubItems.Add(package.Description);
packageListViewItem.Group = package.IsReleased ? packagesList.Groups[0] : packagesList.Groups[1];
packageListViewItem.Tag = package.Version;
Expand Down Expand Up @@ -844,6 +853,15 @@ private async void InitializeEditing()
}
else
{
if (!File.Exists(
Project.Packages.First(item => item.Version == packageVersion.ToString()).LocalPackagePath))
{
Invoke(
new Action(
() => Popup.ShowPopup(this, SystemIcons.Error,
"Edit operation cancelled", "The package file doesn't exist locally and can't be edited locally.", PopupButtons.Ok)));
return;
}
packageEditDialog.IsReleased = false;

try
Expand Down Expand Up @@ -1073,28 +1091,34 @@ private void uploadButton_Click(object sender, EventArgs e)
if (packagesList.SelectedItems.Count == 0)
return;

var version = (UpdateVersion) packagesList.SelectedItems[0].Tag;
var version = new UpdateVersion((string) packagesList.SelectedItems[0].Tag);
#pragma warning disable 4014
UploadPackage(version);
#pragma warning restore 4014
}

/// <summary>
/// Provides a new thread that uploads the package.
/// </summary>
private async void UploadPackage(UpdateVersion packageVersion)
{
await Task.Factory.StartNew(() =>
await TaskEx.Run(() =>
{
if (!File.Exists(
Project.Packages.First(item => item.Version == packageVersion.ToString()).LocalPackagePath))
{
Invoke(
new Action(
() => Popup.ShowPopup(this, SystemIcons.Error,
"Upload operation cancelled", "The package file doesn't exist locally and can't be uploaded to the server.", PopupButtons.Ok)));
return;
}
var updateConfigurationFilePath = Path.Combine(Program.Path, "Projects", Project.Name,
packageVersion.ToString(), "updates.json");
SetUiState(false);
Invoke(new Action(() => loadingLabel.Text = "Getting old configuration..."));
try
{
var updateConfiguration = UpdateConfiguration.Download(_configurationFileUrl, Project.Proxy) ??
Enumerable.Empty<UpdateConfiguration>();
var updateConfiguration = UpdateConfiguration.Download(_configurationFileUrl, Project.Proxy) ?? Enumerable.Empty<UpdateConfiguration>();
_backupConfiguration = updateConfiguration.ToList();
}
catch (Exception ex)
Expand Down Expand Up @@ -1743,6 +1767,7 @@ private async void DeletePackage()
Settings.Default.Reload();
}
Project.Packages.Remove(Project.Packages.First(item => item.Version == (string)((ListViewItem) enumerator.Current).Tag));
UpdateProject.SaveProject(Project.Path, Project);
}
catch (Exception ex)
Expand Down Expand Up @@ -1906,5 +1931,10 @@ private void readOnlyTextBox_KeyDown(object sender, KeyEventArgs e)
((TextBox)sender).SelectAll();
e.Handled = true;
}

private void overviewHeader_Click(object sender, EventArgs e)
{

}
}
}
5 changes: 1 addition & 4 deletions nUpdate.Administration/UI/Dialogs/ProjectDialog.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD0
EAAAAk1TRnQBSQFMAgEBBAEAAUABBwFAAQcBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
EAAAAk1TRnQBSQFMAgEBBAEAAUgBBwFIAQcBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
AwABIAMAAQEBAAEgBgABIP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8AYgADFgEeAx0BKQMf
ASwDGgEkAxsBJgMjATMDOQFfAlQBVgGrAlkBXAHMAlkBXAHMAlkBXAHMA1MBqgMyAVADDAEQAwYBCAMA
AQEDMAFMA0kBiQM9AWkDIQExAyABLgMdASoDGwEmAxgBIgMWAR4DEgEZAxABFQMMARADCQEMAwYBCAME
Expand Down Expand Up @@ -553,9 +553,6 @@
ARhvDLxADPQnWDPQqUgGkI//MwAAgCyIfFYym24AAAAASUVORK5CYII=
</value>
</data>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="packagesContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 61</value>
</metadata>
Expand Down

0 comments on commit e5c0a53

Please sign in to comment.