Skip to content

Commit 39c2bf9

Browse files
Before download check available diskspace
1 parent 3593371 commit 39c2bf9

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

Source/Menu/DownloadContentForm.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ private void DownloadContentButton_Click(object sender, EventArgs e)
9090

9191
// various checks for the directory where the route is installed
9292

93+
DriveInfo dInfo = new DriveInfo(installPathRoute);
94+
95+
long size = Routes[RouteName].InstallSize + Routes[RouteName].DownloadSize;
96+
97+
if (size > (dInfo.AvailableFreeSpace * 1.1))
98+
{
99+
message = Catalog.GetStringFmt("Not enough diskspace on drive {0} ({1}), available {2} kB, needed {3} kB, still continue?",
100+
dInfo.Name,
101+
dInfo.VolumeLabel,
102+
(dInfo.AvailableFreeSpace / 1024).ToString("N0"),
103+
(size / 1024).ToString("N0"));
104+
105+
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
106+
{
107+
// cancelled
108+
return;
109+
}
110+
}
111+
93112
message = Catalog.GetStringFmt("Route to be installed in \"{0}\", are you sure?", installPathRoute);
94113

95114
if (MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)

Source/ORTS.Settings/RouteSettings.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ public class Route
3333
public string DateInstalled { get; set; }
3434
public string Url { get; set; }
3535

36-
public Route(string dateInstalled, string url)
36+
public long DownloadSize;
37+
public long InstallSize;
38+
39+
public Route(string dateInstalled, string url, long downloadSize, long installSize)
3740
{
3841
DateInstalled = dateInstalled;
3942
Url = url;
43+
DownloadSize = downloadSize;
44+
InstallSize = installSize;
4045
}
4146
}
4247

@@ -109,12 +114,14 @@ public void LoadContentAndInstalled()
109114
{
110115
string routeName = result["name"].ToString();
111116
string url = result["url"].ToString();
117+
long downloadSize = convertResultToLong(result, "downloadSize");
118+
long installSize = convertResultToLong(result, "installSize");
112119

113120
if (url.EndsWith(".git") || url.EndsWith(".zip"))
114121
{
115122
if (!Routes.ContainsKey(routeName))
116123
{
117-
Routes.Add(routeName, new RouteSettings.Route("", url));
124+
Routes.Add(routeName, new RouteSettings.Route("", url, downloadSize, installSize));
118125
}
119126
}
120127
}
@@ -130,6 +137,18 @@ public void LoadContentAndInstalled()
130137
return;
131138
}
132139

140+
long convertResultToLong(JToken result, string fieldName)
141+
{
142+
if (result[fieldName] != null)
143+
{
144+
return (long)Convert.ToDouble(result[fieldName].ToString());
145+
}
146+
else
147+
{
148+
return 0;
149+
}
150+
}
151+
133152
private void directoryDelete(string directoryName)
134153
{
135154
if (Directory.Exists(directoryName))

0 commit comments

Comments
 (0)