Skip to content

Commit 42e128a

Browse files
committed
fix: Use only standard built-in compression classes
1 parent 4805f87 commit 42e128a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Source/Orts.Updater/Orts.Updater.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
<DocumentationFile>..\..\Program\Orts.Updater.xml</DocumentationFile>
1717
</PropertyGroup>
1818
<ItemGroup>
19+
<Reference Include="System.IO.Compression" />
1920
<Reference Include="System.Security" />
2021
</ItemGroup>
2122
<ItemGroup>
2223
<ProjectReference Include="..\Orts.Common\Orts.Common.csproj" />
2324
<ProjectReference Include="..\Orts.Settings\Orts.Settings.csproj" />
2425
</ItemGroup>
2526
<ItemGroup>
26-
<PackageReference Include="DotNetZip" Version="1.16.0" />
2727
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.355802">
2828
<PrivateAssets>all</PrivateAssets>
2929
</PackageReference>

Source/Orts.Updater/UpdateManager.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

18-
using Ionic.Zip;
1918
using Newtonsoft.Json;
2019
using ORTS.Common;
2120
using ORTS.Settings;
@@ -24,6 +23,7 @@
2423
using System.ComponentModel;
2524
using System.Diagnostics;
2625
using System.IO;
26+
using System.IO.Compression;
2727
using System.Linq;
2828
using System.Net;
2929
using System.Runtime.InteropServices;
@@ -413,14 +413,22 @@ void DownloadUpdate(int progressMin, int progressLength)
413413

414414
void ExtractUpdate(int progressMin, int progressLength)
415415
{
416-
using (var zip = ZipFile.Read(FileUpdateStage))
416+
using (var zip = ZipFile.OpenRead(FileUpdateStage))
417417
{
418-
zip.ExtractProgress += (object sender, ExtractProgressEventArgs e) =>
418+
for (var index = 0; index < zip.Entries.Count; index++)
419419
{
420-
if (e.EventType == ZipProgressEventType.Extracting_BeforeExtractEntry)
421-
TriggerApplyProgressChanged(progressMin + progressLength * e.EntriesExtracted / e.EntriesTotal);
422-
};
423-
zip.ExtractAll(PathUpdateStage, ExtractExistingFileAction.OverwriteSilently);
420+
TriggerApplyProgressChanged(progressMin + progressLength * index / zip.Entries.Count);
421+
422+
var absolutePath = Path.GetFullPath(Path.Combine(PathUpdateStage, zip.Entries[index].FullName));
423+
if (!absolutePath.StartsWith(PathUpdateStage))
424+
throw new IOException("Invalid update: attempting to extract outside staging area");
425+
426+
if (Path.GetFileName(absolutePath).Length > 0)
427+
{
428+
Directory.CreateDirectory(Path.GetDirectoryName(absolutePath));
429+
zip.Entries[index].ExtractToFile(absolutePath, true);
430+
}
431+
}
424432
}
425433

426434
File.Delete(FileUpdateStage);

0 commit comments

Comments
 (0)