You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb none ============================ MAJOR FEATURES & CHANGES ============================ Change 3550452 by Ben.Marsh UAT: Improve readability of error message when an editor commandlet fails with an error code. Change 3551179 by Ben.Marsh Add methods for reading text files into an array of strings. Change 3551260 by Ben.Marsh Core: Change FFileHelper routines to use enum classes for flags. Change 3555697 by Gil.Gribb Fixed a rare crash when the asset registry scanner found old cooked files with package level compression. #jira UE-47668 Change 3556464 by Ben.Marsh UGS: If working in a virtual stream, use the name of the first non-virtual ancestor for writing version files. Change 3557630 by Ben.Marsh Allow the network version to be set via Build.version if it's not overriden from Version.h. Change 3561357 by Gil.Gribb Fixed crashes related to loading old unversioned files in the editor. #jira UE-47806 Change 3565711 by Graeme.Thornton PR #3839: Make non-encoding specific Base64 functions accessible (Contributed by stfx) Change 3565864 by Robert.Manuszewski Temp fix for a race condition with the async loading thread enabled - caching the linker in case it gets removed (but not deleted) from super class object. Change 3569022 by Ben.Marsh PR #3849: Update gitignore (Contributed by mhutch) Change 3569113 by Ben.Marsh Fix Japanese errors not displaying correctly in the cook output log. #jira UE-47746 Change 3569486 by Ben.Marsh UGS: Always sync the Enterprise folder if the selected .uproject file has the "Enterprise" flag set. Change 3570483 by Graeme.Thornton Minor C# cleanups. Removing some redundant "using" calls which also cause dotnetcore compile errors Change 3570513 by Robert.Manuszewski Fix for a race condition with async loading thread enabled. Change 3570664 by Ben.Marsh UBT: Use P/Invoke to determine number of physical processors on Windows rather than using WMI. Starting up WMIC adds 2.5 seconds to build times, and is not compatible with .NET core. Change 3570708 by Robert.Manuszewski Added ENABLE_GC_OBJECT_CHECKS macro to be able to quickly toggle UObject pointer checks in shipping builds when the garbage collector is running. Change 3571592 by Ben.Marsh UBT: Allow running with -installed without creating [InstalledPlatforms] entries in BaseEngine.ini. If there is no HasInstalledPlatformInfo=true setting, assume that all platforms are still available. Change 3572215 by Graeme.Thornton UBT - Remove some unnecessary using directives - Point SN-DBS code at the new Utils.GetPhysicalProcessorCount call, rather than trying to calculate it itself Change 3572437 by Robert.Manuszewski Game-specific fix for lazy object pointer issues in one of the test levels. The previous fix had to be partially reverted due to side-effects. #jira UE-44996 Change 3572480 by Robert.Manuszewski MaterialInstanceCollections will no longer be added to GC clusters to prevent materials staying around in memory for too long Change 3573547 by Ben.Marsh Add support for displaying log timestamps in local time. Set LogTimes=Local in *Engine.ini, or pass -LocalLogTimes on the command line. Change 3574562 by Robert.Manuszewski PR #3847: Add GC callbacks for script integrations (Contributed by mhutch) Change 3575017 by Ben.Marsh Move some functions related to generating window resolutions out of Core (FParse::Resolution, GenerateConvenientWindowedResolutions). Also remove a few headers from shared PCHs prior to splitting application functionality out of Core. Change 3575689 by Ben.Marsh Add a fixed URL for opening the API documentation, so it works correctly in "internal" and "perforce" builds. Change 3575934 by Steve.Robb Fix for nested preprocessor definitions. Change 3575961 by Steve.Robb Fix for nested zeros. Change 3576297 by Robert.Manuszewski Material resources will now be discarded in PostLoad (Game Thread) instead of in Serialize (potentially Async Loading Thread) so that shader deregistration doesn't assert when done from a different thread than the game thread. #jira FORT-38977 Change 3576366 by Ben.Marsh Add shim functions to allow redirecting FPlatformMisc::ClipboardCopy()/ClipboardPaste() to FPlatformApplicationMisc::ClipboardCopy()/ClipboardPaste() while they are deprecated. Change 3578290 by Graeme.Thornton Changes to Ionic zip library to allow building on dot net core Change 3578291 by Graeme.Thornton Ionic zip library binaries built for .NET Core Change 3578354 by Graeme.Thornton Added FBase64::GetDecodedDataSize() to determine the size of bytes of a decoded base64 string Change 3578674 by Robert.Manuszewski After loading packages flush linker cache on uncooked platforms to free precache memory Change 3579068 by Steve.Robb Fix for CLASS_Intrinsic getting stomped. Fix to EClassFlags so that they are visible in the debugger. Re-added mysteriously-removed comments. Change 3579228 by Steve.Robb BOM removed. Change 3579297 by Ben.Marsh Fix exception if a plugin lists the same module twice. #jira UE-48232 Change 3579898 by Robert.Manuszewski When creating GC clusters and asserting due to objects still being pending load, the object name and cluster name will now be logged with the assert. Change 3579983 by Robert.Manuszewski More fixes for freeing linker cache memory in the editor. Change 3580012 by Graeme.Thornton Remove redundant copy of FileReference.cs Change 3580408 by Ben.Marsh Validate that arguments passed to the checkf macro are valid sprintf types, and fix up a few places which are currently incorrect. Change 3582104 by Graeme.Thornton Added a dynamic compilation path that uses the latest roslyn apis. Currently only used by the .NET Core path. Change 3582131 by Graeme.Thornton #define out some PerformanceCounter calls that don't exist in .NET Core. They're only used by mono-specific calls anyway. Change 3582645 by Ben.Marsh PR #3879: fix bug when creating a new VS2017 C++ project (Contributed by mnannola) #jira UE-48192 Change 3583955 by Robert.Manuszewski Support for EDL cooked packages in the editor Change 3584035 by Graeme.Thornton Split RunExternalExecutable into RunExternaNativelExecutable and RunExternalDotNETExecutable. When running under .NET Core, externally launched DotNET utilities must be launched via the 'dotnet' proxy to work correctly. Change 3584177 by Robert.Manuszewski Removed unused member variable (FArchiveAsync2::bKeepRestOfFilePrecached) Change 3584315 by Ben.Marsh Move Android JNI accessor functions into separate header, to decouple it from the FAndroidApplication class. Change 3584370 by Ben.Marsh Move hooks which allow platforms to load any modules into the FPlatformApplicationMisc classes. Change 3584498 by Ben.Marsh Move functions for getting and setting the hardware window pointer onto the appropriate platform window classes. Change 3585003 by Steve.Robb Fix for TChunkedArray ranged-for iteration. #jira UE-48297 Change 3585235 by Ben.Marsh Remove LogEngine extern from Core; use the platform log channels instead. Change 3585942 by Ben.Marsh Move MessageBoxExt() implementation into application layer for platforms that require it. Change 3587071 by Ben.Marsh Move Linux's UngrabAllInput() function into a callback, so DebugBreak still works without SDL. Change 3587161 by Ben.Marsh Remove headers which will be stripped out of the Core module from Core.h and PlatformIncludes.h. Change 3587579 by Steve.Robb Fix for Children list not being rebuilt after hot reload. Change 3587584 by Graeme.Thornton Logging improvements for pak signature check failures - Added "PakCorrupt" console command which corrupts the master signature table - Added some extra log information about which block failed - Re-hash the master signature table and to make sure that it hasn't changed since startup - Moved the ensure around so that some extra logging messages can make it out before the ensure is hit - Added PAK_SIGNATURE_CHECK_FAILS_ARE_FATAL to IPlatformFilePak.h so we have a single place to make signature check failures fatal again Change 3587586 by Graeme.Thornton Changes to make UBT build and run on .NET Core - Added *_DNC csproj files for DotNETUtilities and UnrealBuildTool projects which contain the .NET Core build setups - VCSharpProjectFile can no be asked for the CsProjectInfo for a particular configuration, which is cached for future use - After loading VCSharpProjectFiles, .NET Core based projects will be excluded unless generating VSCode projects Change 3587953 by Steve.Robb Allow arbitrary UENUM initializers for enumerators. Editor-only data UENUM support. Enumerators named MAX are now treated as the UENUM's maximum, and will not cause a MAX+1 value to be generated. #jira UE-46274 Change 3589827 by Graeme.Thornton More fixes for VSCode project generation and for UBT running on .NET Core - Use a different file extension for rules assemblies when build on .NET Core, so they never get used by their counterparts - UEConsoleTraceListener supports stdout/stderror constructor parameter and outputs to the appropriate channel - Added documentation for UEConsoleTraceListener - All platforms .NET project compilation tasks/launch configs now use "dotnet" and not the normal batch files - Restored the default UBT log verbosity to "Log" rather than "VeryVeryVerbose" - Renamed assemblies for .NETCore versions of DotNETUtilities and UnrealBuildTool so they don't conflict with the output of the existing .NET Desktop Framework stuff Change 3589868 by Graeme.Thornton Separate .NET Core projects for UBT and DotNETCommon out into their own directories so that their intermediates don't overlap with the standard .NET builds, causing failures. UBT registers ONLY .NET Core C# projects when generating VSCode solutions, and ONLY standard C# projects in all other cases Change 3589919 by Robert.Manuszewski Fixing crash when cooking textures that have already been cooked for EDL (support for cooked content in the editor) Change 3589940 by Graeme.Thornton Force UBT to think it's running on mono when actually running on .NET Core. Disables a lot of windows specific code paths. Change 3590078 by Graeme.Thornton Fully disable automatic assembly info generation in .NET Core projects Change 3590534 by Robert.Manuszewski Marking UObject as intrinsic clas to fix a crash on UFE startup. Change 3591498 by Gil.Gribb UE4 - Fixed several edge cases in the low level async loading code, especially around cancellation. Also PakFileTest is a console command which can be used to stress test pak file loading. Change 3591605 by Gil.Gribb UE4 - Follow up to fixing several edge cases in the low level async loading code. Change 3592577 by Graeme.Thornton .NET Core C# projects now reference source files explicitly, to stop it accidentally compiling various intermediates Change 3592684 by Steve.Robb Fix for EObjectFlags being passed as the wrong argument to csgCopyBrush. Change 3592710 by Steve.Robb Fix for invalid casts in ListProps command. Some name changes in command output. Change 3592715 by Ben.Marsh Move Windows event log code into cpp file, and expose it to other modules even if it's not enabled by default. Change 3592767 by Gil.Gribb UE4 - Changed the logic so that engine UObjects boot before anything else. The engine classes are known to be cycle-free, so we will get them done before moving onto game modules. Change 3592770 by Gil.Gribb UE4 - Fixed a race condition with async read completion in the prescence of cancels. Change 3593090 by Steve.Robb Better error message when there two clashing type names are found. Change 3593697 by Steve.Robb VisitTupleElements function, which calls a functor for each element in the tuple. Change 3595206 by Ben.Marsh Include additional diagnostics for missing imports when a module load fails. Change 3596140 by Graeme.Thornton Batch file for running MSBuild Change 3596267 by Steve.Robb Thread safety fix to FPaths::GetProjectFilePath(). Change 3596271 by Robert.Manuszewski Added code to verify compression flags in package file summary to avoid cases where corrupt packages are crashing the editor #jira UE-47535 Change 3596283 by Steve.Robb Redundant casts removed from UHT. Change 3596303 by Ben.Marsh EC: Improve parsing of Android Clang errors and warnings, which are formatted as MSVC diagnostics to allow go-to-line clicking in the Output Window. Change 3596337 by Ben.Marsh UBT: Format messages about incorrect headers in a way that makes them clickable from Visual Studio. Change 3596367 by Steve.Robb Iterator checks in ranged-for on TMap, TSet and TSparseArray. Change 3596410 by Gil.Gribb UE4 - Improved some error messages on runtime failures in the EDL. Change3596532by Ben.Marsh UnrealVS: Fix setting command line to empty not affecting property sheet. Also remove support for VS2013. #jira UE-48119 Change 3596631 by Steve.Robb Tool which takes a .map file and a .objmap file (from UBT) and creates a report which shows the size of all the symbols contributed by the source code per-folder. Change 3596807 by Ben.Marsh Improve Intellisense when generated headers are missing or out of date (eg. line numbers changed, etc...). These errors seem to be masked by VAX, but are present when using the default Visual Studio Intellisense. * UCLASS macro is defined to empty when __INTELLISENSE__ is defined. Previous macro was preventing any following class declaration being parsed correctly if generated code was out of date, causing squiggles over all class methods/variables. * Insert a semicolon after each expanded GENERATED_BODY macro, so that if it parses incorrectly, the compiler can still continue parsing the next declaration. Change 3596957 by Steve.Robb UBT can be used to write out an .objsrcmap file for use with the MapFileParser. Renaming of ObjMap to ObjSrcMap in MapFileParser. Change 3597213 by Ben.Marsh Remove AutoReporter. We don't support this any more. Change 3597558 by Ben.Marsh UGS: Allow adding custom actions to the context menu for right clicking on a changelist. Actions are specified in the project's UnrealEngine.ini file, with the following syntax: +ContextMenu=(Label="This is the menu item", Execute="foo.exe", Arguments="bar") The standard set of variables for custom tools is expanded in each parameter (eg. $(ProjectDir), $(EditorConfig), etc...), plus the $(Change) variable. Change 3597982 by Ben.Marsh Add an option to allow overriding the local DDC path from the editor (under Editor Preferences > Global > Local Derived Data Cache). #jira UE-47173 Change 3598045 by Ben.Marsh UGS: Add variables for stream and client name, and the ability to escape any variables for URIs using the syntax $(VariableName:URI). Change 3599214 by Ben.Marsh Avoid string duplication when comparing extensions. Change 3600038 by Steve.Robb Fix for maps being modified during iteration in cache compaction. Change 3600136 by Steve.Robb GitHub #3538 : Fixed a bug with the handling of 'TMap' key/value types in the UnrealHeaderTool Change 3600214 by Steve.Robb More accurate error message when unsupported template parameters are provided in a TSet property. Change 3600232 by Ben.Marsh UBT: Force UHT to run again if the .build.cs file for a module has changed. #jira UE-46119 Change 3600246 by Steve.Robb GitHub #3045 : allow multiple interface definition in a file Change 3600645 by Ben.Marsh Convert QAGame to Include-What-You-Use. Change 3600897 by Ben.Marsh Fix invalid path (multiple slashes) in LibCurl.build.cs. Causes exception when scanning for includes. Change 3601558 by Graeme.Thornton Simple first pass VSCode editor integration plugin Change 3601658 by Graeme.Thornton Enable intellisense generation for VS Code project files and setup include paths properly Change 3601762 by Ben.Marsh UBT: Add support for adaptive non-unity builds when working from a Git repository. The ISourceFileWorkingSet interface is now used to query files belonging to the working set, and has separate implementations for Perforce (PerforceSourceFileWorkingSet) and Git (GitSourceFileWorkingSet). The Git implementation is used if a .git directory is found in the directory containing the Engine folder, the directory containing the project file, or the parent directory of the project file, and spawns a "git status" process in the background to determine which files are untracked or staged. Several new settings are supported in BuildConfiguration.xml to allow modifying default behavior: <SourceFileWorkingSet> <Provider>Default</Provider> <!-- May be None, Default, Git or Perforce --> <RepositoryPath></RepositoryPath> <!-- Specifies the path to the repository, relative to the directory containing the Engine folder. If not set, tries to find a .git directory in the locations listed above. --> <GitPath>git</GitPath> <!-- Specifies the path to the Git executable. Defaults to "git", which assumes that it will be on the PATH --> </SourceFileWorkingSet> Change 3604032 by Graeme.Thornton First attempt at automatically detecting the existance and location of visual studio code in the source code accessor module. Only works for windows. Change 3604038 by Graeme.Thornton Added FSourceCodeNavigation::GetSelectedSourceCodeIDE() which returns the name of the selected source code accessor. Replaced all usages of FSourceCodeNavigation::GetSuggestedSourceCodeIDE() with GetSelectedSourceCodeIDE(), where the message is referring to the opening or editing of code. Change 3604106 by Steve.Robb GitHub #3561 : UE-44950: Don't see all caps struct constructor as macro Change 3604192 by Steve.Robb GitHub #3911 : Improving ToUpper/ToLower efficiency Change 3604273 by Graeme.Thornton IWYU build fixes when malloc profiler is enabled Change 3605457 by Ben.Marsh Fix race for intiialization of ThreadID variable on FRunnableThreadWin, and restore a previous check that was working around it. Change 3606720 by James.Hopkin Dave Ratti's fix to character base recursion protection code - was missing a GetOwner call, instead attempting to cast a component to a pawn. Change 3606807 by Graeme.Thornton Disabled optimizations around FShooterStyle::Create(), which was crashing in Win64 shipping game builds due to some known compiler issue. Same variety of fix as BenZ did in CL 3567741. Change 3607026 by James.Hopkin Fixed incorrect ABrush cast - was attempting to cast a UModel to ABrush, which can never succeed Change 3607142 by Graeme.Thornton UBT - Minor refactor of BackgroundProcess shutdown in SourceFileWorkingSet. Check whether the process has already exited before trying to kill it during Dispose. Change 3607146 by Ben.Marsh UGS: Fix exception due to formatting string when Perforce throws an error. Change 3607147 by Steve.Robb Efficiency fix for integer properties, which were causing a property mismatch and thus a tag lookup every time. Float and double conversion support added to int properties. NAME_DoubleProperty added. Fix for converting enum class enumerators > 255 to int properties. Change 3607516 by Ben.Marsh PR #3935: Fix DECLARE_DELEGATE_NineParams, DECLARE_MULTICAST_DELEGATE_NineParams. (Contributed by enginevividgames) Change 3610421 by Ben.Marsh UAT: Move help for RebuildLightMapsCommand into attributes, so they display when running with -help. Change 3610657 by Ben.Marsh UAT: Unify initialization of command environment for build machines and local execution. Always derive parameters which aren't manually set via environment variables. Change 3611000 by Ben.Marsh UAT: Remove the -ForceLocal command line option. Settings are now determined automatically, independently of the -Buildmachine argument. Change 3612471 by Ben.Marsh UBT: Move FastJSON into DotNETUtilities. Change 3613479 by Ben.Marsh UBT: Remove the bIsCodeProject flag from UProjectInfo. This was only really being used to determine which projects to generate an IDE project for, so it is now checked in the project file generator. Change 3613910 by Ben.Marsh UBT: Remove unnecessary code to guess a project from the target name; doesn't work due to init order, actual project is determined later. Change 3614075 by Ben.Marsh UBT: Remove hacks for testing project file attributes by name. Change 3614090 by Ben.Marsh UBT: Remove global lookup of project by name. Projects should be explicitly specified by path when necessary. Change 3614488 by Ben.Marsh UBT: Prevent annoying (but handled) exception when constructing SQLiteModuleSupport objects with -precompile enabled. Change 3614490 by Ben.Marsh UBT: Simplify generation of arguments for building intellisense; determine the platform/configuration to build from the project file generation code, rather than inside the target itself. Change 3614962 by Ben.Marsh UBT: Move the VS2017 strict conformance mode (/permissive-) behind a command line option (-Strict), and disable it by default. Building with this mode is not guaranteed to work correctly without updated Windows headers. Change 3615416 by Ben.Marsh EC: Include an icon showing the overall status of a build in the grid view. Change 3615713 by Ben.Marsh UBT: Delete any files in output directories which match output files in other directories. Allows automatically deleting build products which are moved into another folder. #jira UE-48987 Change 3616652 by Ben.Marsh Plugins: Fix incorrect dialog when binaries for a plugin are missing. Should only prompt to disable if starting a content-only project. #jira UE-49007 Change 3616680 by Ben.Marsh Add the CodeAPI-HTML.tgz file into the installed engine build. Change 3616767 by Ben.Marsh Plugins: Tweak error message if the FModuleManager::IsUpToDate() function returns false for a plugin module; the module may be missing, not just incompatible. Change 3616864 by Ben.Marsh Cap the length of the temporary package name during save, to prevent excessively long filenames going over the limit once a GUID is appended. #jira UE-48711 Change 3619964 by Ben.Marsh UnrealVS: Fix single file compile for foreign projects, where the command line contains $(SolutionDir) and $(ProjectName) variables. Change 3548930 by Ben.Marsh UBT: Remove UEBuildModuleCSDLL; there is no codepath that still supports creating them. Remove the remaining UEBuildModule/UEBuildModuleCPP abstraction. Change 3558056 by Ben.Marsh Deprecate FString::Trim() and FString::TrimTrailing(), and replace them with separate versions to mutate (TrimStartInline(), TrimEndInline()) or return by copy (TrimStart(), TrimEnd()). Also add a functions to trim whitespace from both ends of a string (TrimStartAndEnd(), TrimStartAndEndInline()). Change 3563309 by Graeme.Thornton Moved some common C# classes into the DotNETCommon assembly Change 3570283 by Graeme.Thornton Move some code out of RPCUtility and into DotNETCommon, removing the dependency between the two projects Added UEConsoleTraceListener to replace ConsoleTraceListener, which doesn't exist in DotNetCore Change 3572811 by Ben.Marsh UBT: Add -enableasan / -enabletsan command line options and bEnableAddressSanitizer / bEnableThreadSanitizer settings in BuildConfiguration.xml (and remove environment variables). Change 3573397 by Ben.Marsh UBT: Create a <ExeName>.version file for every target built by UBT, in the same JSON format as Engine/Build/Build.version. This allows monolithic targets to read a version number at runtime, unlike when it's embedded in a modules file, and allows creating versioned client executables that will work with versioned servers when syncing through UGS. Change 3575659 by Ben.Marsh Remove CHM API documentation. Change 3582103 by Graeme.Thornton Simple ResX writer implemetation that the xbox deloyment code can use instead of the one from the windows forms assembly, which isn't supported on .NET Core Removed reference to System.Windows.Form from UBT. Change 3584113 by Ben.Marsh Move key-mapping functionality into the InputCore module. Change 3584278 by Ben.Marsh Move FPlatformMisc::RequestMinimize() into FPlatformApplicationMisc. Change 3584453 by Ben.Marsh Move functionality for querying device display density to FApplicationMisc, due to dependence on application-level functionality on mobile platforms. Change 3585301 by Ben.Marsh Move PlatformPostInit() into an FPlatformApplicationMisc function. Change 3587050 by Ben.Marsh Move IsThisApplicationForeground() into FPlatformApplicationMisc. Change 3587059 by Ben.Marsh Move RequiresVirtualKeyboard() into FPlatformApplicationMisc. Change3587119by Ben.Marsh Move GetAbsoluteLogFilename() into FPlatformMisc. Change 3587800 by Steve.Robb Fixes to container visualizers for types whose pointer type isn't simply Type*. Change 3588393 by Ben.Marsh Move platform output devices into their own headers. Change 3588868 by Ben.Marsh Move creation of console, error and warning output devices int PlatformApplicationMisc. Change 3589879 by Graeme.Thornton All automation projects now have a reference to DotNETUtilities Fixed a build error in the WEX automation library Change 3590034 by Ben.Marsh Move functionality related to windowing and input out of the Core module and into an ApplicationCore module, so it is possible to build utilities with Core without adding dependencies on XInput (Windows), SDL (Linux), and OpenGL (Mac). Change 3593754 by Steve.Robb Fix for tuple debugger visualization. Change 3597208 by Ben.Marsh Move CrashReporter out of a public folder; it's not in a form that is usable by subscribers and licensees. Change 3600163 by Ben.Marsh UBT: Simplify how targets are cleaned. Delete all intermediate folders for a platform/configuration, and delete any build products matching the UE4 naming convention for that target, rather than relying on the current build configuration or list of previous build products. This will ensure that build products which are no longer being generated will also be cleaned. #jira UE-46725 Change 3604279 by Graeme.Thornton Move pre/post garbage collection delegates into accessor functions so they can be used by globally constructed objects Change 3606685 by James.Hopkin Removed redundant 'Cast's (casting to either the same type or a base). In SClassViewer, replaced cast with TAssetPtr::operator* call to get the wrapped UClass. Also removed redundant 'IsA's from AnimationRetargetContent::AddRemappedAsset in EditorAnimUtils.cpp. Change 3610950 by Ben.Marsh UAT: Simplify logic for detecting Perforce settings, using environment variables if they are set, otherwise falling back to detecting them. Removes special cases for build machines, and makes it simpler to set up UAT commands on builders outside Epic. Change 3610991 by Ben.Marsh UAT: Use the correct P4 settings to detect settings if only some parameters are specified on the command line. Change 3612342 by Ben.Marsh UBT: Change JsonObject.Read() to take a FileReference parameter. Change 3612362 by Ben.Marsh UBT: Remove some more cases of paths being passed as strings rather than using FileReference objects. Change 3619128 by Ben.Marsh Include builder warnings and errors in the notification emails for automated tests, otherwise it's difficult to track down non-test failures. [CL 3620189 by Ben Marsh in Main branch]
911 lines
33 KiB
C#
911 lines
33 KiB
C#
// Shared.cs
|
|
// ------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) 2006-2011 Dino Chiesa.
|
|
// All rights reserved.
|
|
//
|
|
// This code module is part of DotNetZip, a zipfile class library.
|
|
//
|
|
// ------------------------------------------------------------------
|
|
//
|
|
// This code is licensed under the Microsoft Public License.
|
|
// See the file License.txt for the license details.
|
|
// More info on: http://dotnetzip.codeplex.com
|
|
//
|
|
// ------------------------------------------------------------------
|
|
//
|
|
// Last Saved: <2011-August-02 19:41:01>
|
|
//
|
|
// ------------------------------------------------------------------
|
|
//
|
|
// This module defines some shared utility classes and methods.
|
|
//
|
|
// Created: Tue, 27 Mar 2007 15:30
|
|
//
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Security.Permissions;
|
|
|
|
namespace Ionic.Zip
|
|
{
|
|
/// <summary>
|
|
/// Collects general purpose utility methods.
|
|
/// </summary>
|
|
internal static class SharedUtilities
|
|
{
|
|
/// private null constructor
|
|
//private SharedUtilities() { }
|
|
|
|
// workitem 8423
|
|
public static Int64 GetFileLength(string fileName)
|
|
{
|
|
if (!File.Exists(fileName))
|
|
throw new System.IO.FileNotFoundException(fileName);
|
|
|
|
long fileLength = 0L;
|
|
FileShare fs = FileShare.ReadWrite;
|
|
#if !NETCF
|
|
// FileShare.Delete is not defined for the Compact Framework
|
|
fs |= FileShare.Delete;
|
|
#endif
|
|
using (var s = File.Open(fileName, FileMode.Open, FileAccess.Read, fs))
|
|
{
|
|
fileLength = s.Length;
|
|
}
|
|
return fileLength;
|
|
}
|
|
|
|
|
|
[System.Diagnostics.Conditional("NETCF")]
|
|
public static void Workaround_Ladybug318918(Stream s)
|
|
{
|
|
// This is a workaround for this issue:
|
|
// https://connect.microsoft.com/VisualStudio/feedback/details/318918
|
|
// It's required only on NETCF.
|
|
s.Flush();
|
|
}
|
|
|
|
|
|
#if LEGACY
|
|
/// <summary>
|
|
/// Round the given DateTime value to an even second value.
|
|
/// </summary>
|
|
///
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Round up in the case of an odd second value. The rounding does not consider
|
|
/// fractional seconds.
|
|
/// </para>
|
|
/// <para>
|
|
/// This is useful because the Zip spec allows storage of time only to the nearest
|
|
/// even second. So if you want to compare the time of an entry in the archive with
|
|
/// it's actual time in the filesystem, you need to round the actual filesystem
|
|
/// time, or use a 2-second threshold for the comparison.
|
|
/// </para>
|
|
/// <para>
|
|
/// This is most nautrally an extension method for the DateTime class but this
|
|
/// library is built for .NET 2.0, not for .NET 3.5; This means extension methods
|
|
/// are a no-no.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <param name="source">The DateTime value to round</param>
|
|
/// <returns>The ruonded DateTime value</returns>
|
|
public static DateTime RoundToEvenSecond(DateTime source)
|
|
{
|
|
// round to nearest second:
|
|
if ((source.Second % 2) == 1)
|
|
source += new TimeSpan(0, 0, 1);
|
|
|
|
DateTime dtRounded = new DateTime(source.Year, source.Month, source.Day, source.Hour, source.Minute, source.Second);
|
|
//if (source.Millisecond >= 500) dtRounded = dtRounded.AddSeconds(1);
|
|
return dtRounded;
|
|
}
|
|
#endif
|
|
|
|
#if YOU_LIKE_REDUNDANT_CODE
|
|
internal static string NormalizePath(string path)
|
|
{
|
|
// remove leading single dot slash
|
|
if (path.StartsWith(".\\")) path = path.Substring(2);
|
|
|
|
// remove intervening dot-slash
|
|
path = path.Replace("\\.\\", "\\");
|
|
|
|
// remove double dot when preceded by a directory name
|
|
var re = new System.Text.RegularExpressions.Regex(@"^(.*\\)?([^\\\.]+\\\.\.\\)(.+)$");
|
|
path = re.Replace(path, "$1$3");
|
|
return path;
|
|
}
|
|
#endif
|
|
|
|
private static System.Text.RegularExpressions.Regex doubleDotRegex1 =
|
|
new System.Text.RegularExpressions.Regex(@"^(.*/)?([^/\\.]+/\\.\\./)(.+)$");
|
|
|
|
private static string SimplifyFwdSlashPath(string path)
|
|
{
|
|
if (path.StartsWith("./")) path = path.Substring(2);
|
|
path = path.Replace("/./", "/");
|
|
|
|
// Replace foo/anything/../bar with foo/bar
|
|
path = doubleDotRegex1.Replace(path, "$1$3");
|
|
return path;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Utility routine for transforming path names from filesystem format (on Windows that means backslashes) to
|
|
/// a format suitable for use within zipfiles. This means trimming the volume letter and colon (if any) And
|
|
/// swapping backslashes for forward slashes.
|
|
/// </summary>
|
|
/// <param name="pathName">source path.</param>
|
|
/// <returns>transformed path</returns>
|
|
public static string NormalizePathForUseInZipFile(string pathName)
|
|
{
|
|
// boundary case
|
|
if (String.IsNullOrEmpty(pathName)) return pathName;
|
|
|
|
// trim volume if necessary
|
|
if ((pathName.Length >= 2) && ((pathName[1] == ':') && (pathName[2] == '\\')))
|
|
pathName = pathName.Substring(3);
|
|
|
|
// swap slashes
|
|
pathName = pathName.Replace('\\', '/');
|
|
|
|
// trim all leading slashes
|
|
while (pathName.StartsWith("/")) pathName = pathName.Substring(1);
|
|
|
|
return SimplifyFwdSlashPath(pathName);
|
|
}
|
|
|
|
static System.Text.Encoding utf8 = System.Text.Encoding.GetEncoding("UTF-8");
|
|
#if NET_CORE
|
|
public static System.Text.Encoding ibm437 = utf8;
|
|
#else
|
|
public static System.Text.Encoding ibm437 = System.Text.Encoding.GetEncoding("IBM437");
|
|
#endif
|
|
|
|
internal static byte[] StringToByteArray(string value, System.Text.Encoding encoding)
|
|
{
|
|
byte[] a = encoding.GetBytes(value);
|
|
return a;
|
|
}
|
|
internal static byte[] StringToByteArray(string value)
|
|
{
|
|
return StringToByteArray(value, ibm437);
|
|
}
|
|
|
|
//internal static byte[] Utf8StringToByteArray(string value)
|
|
//{
|
|
// return StringToByteArray(value, utf8);
|
|
//}
|
|
|
|
//internal static string StringFromBuffer(byte[] buf, int maxlength)
|
|
//{
|
|
// return StringFromBuffer(buf, maxlength, ibm437);
|
|
//}
|
|
|
|
internal static string Utf8StringFromBuffer(byte[] buf)
|
|
{
|
|
return StringFromBuffer(buf, utf8);
|
|
}
|
|
|
|
internal static string StringFromBuffer(byte[] buf, System.Text.Encoding encoding)
|
|
{
|
|
// this form of the GetString() method is required for .NET CF compatibility
|
|
string s = encoding.GetString(buf, 0, buf.Length);
|
|
return s;
|
|
}
|
|
|
|
|
|
internal static int ReadSignature(System.IO.Stream s)
|
|
{
|
|
int x = 0;
|
|
try { x = _ReadFourBytes(s, "n/a"); }
|
|
catch (BadReadException) { }
|
|
return x;
|
|
}
|
|
|
|
|
|
internal static int ReadEntrySignature(System.IO.Stream s)
|
|
{
|
|
// handle the case of ill-formatted zip archives - includes a data descriptor
|
|
// when none is expected.
|
|
int x = 0;
|
|
try
|
|
{
|
|
x = _ReadFourBytes(s, "n/a");
|
|
if (x == ZipConstants.ZipEntryDataDescriptorSignature)
|
|
{
|
|
// advance past data descriptor - 12 bytes if not zip64
|
|
s.Seek(12, SeekOrigin.Current);
|
|
// workitem 10178
|
|
Workaround_Ladybug318918(s);
|
|
x = _ReadFourBytes(s, "n/a");
|
|
if (x != ZipConstants.ZipEntrySignature)
|
|
{
|
|
// Maybe zip64 was in use for the prior entry.
|
|
// Therefore, skip another 8 bytes.
|
|
s.Seek(8, SeekOrigin.Current);
|
|
// workitem 10178
|
|
Workaround_Ladybug318918(s);
|
|
x = _ReadFourBytes(s, "n/a");
|
|
if (x != ZipConstants.ZipEntrySignature)
|
|
{
|
|
// seek back to the first spot
|
|
s.Seek(-24, SeekOrigin.Current);
|
|
// workitem 10178
|
|
Workaround_Ladybug318918(s);
|
|
x = _ReadFourBytes(s, "n/a");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (BadReadException) { }
|
|
return x;
|
|
}
|
|
|
|
|
|
internal static int ReadInt(System.IO.Stream s)
|
|
{
|
|
return _ReadFourBytes(s, "Could not read block - no data! (position 0x{0:X8})");
|
|
}
|
|
|
|
private static int _ReadFourBytes(System.IO.Stream s, string message)
|
|
{
|
|
int n = 0;
|
|
byte[] block = new byte[4];
|
|
#if NETCF
|
|
// workitem 9181
|
|
// Reading here in NETCF sometimes reads "backwards". Seems to happen for
|
|
// larger files. Not sure why. Maybe an error in caching. If the data is:
|
|
//
|
|
// 00100210: 9efa 0f00 7072 6f6a 6563 742e 6963 7750 ....project.icwP
|
|
// 00100220: 4b05 0600 0000 0006 0006 0091 0100 008e K...............
|
|
// 00100230: 0010 0000 00 .....
|
|
//
|
|
// ...and the stream Position is 10021F, then a Read of 4 bytes is returning
|
|
// 50776369, instead of 06054b50. This seems to happen the 2nd time Read()
|
|
// is called from that Position..
|
|
//
|
|
// submitted to connect.microsoft.com
|
|
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=318918#tabs
|
|
//
|
|
for (int i = 0; i < block.Length; i++)
|
|
{
|
|
n+= s.Read(block, i, 1);
|
|
}
|
|
#else
|
|
n = s.Read(block, 0, block.Length);
|
|
#endif
|
|
if (n != block.Length) throw new BadReadException(String.Format(message, s.Position));
|
|
int data = unchecked((((block[3] * 256 + block[2]) * 256) + block[1]) * 256 + block[0]);
|
|
return data;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Finds a signature in the zip stream. This is useful for finding
|
|
/// the end of a zip entry, for example, or the beginning of the next ZipEntry.
|
|
/// </summary>
|
|
///
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Scans through 64k at a time.
|
|
/// </para>
|
|
///
|
|
/// <para>
|
|
/// If the method fails to find the requested signature, the stream Position
|
|
/// after completion of this method is unchanged. If the method succeeds in
|
|
/// finding the requested signature, the stream position after completion is
|
|
/// direct AFTER the signature found in the stream.
|
|
/// </para>
|
|
/// </remarks>
|
|
///
|
|
/// <param name="stream">The stream to search</param>
|
|
/// <param name="SignatureToFind">The 4-byte signature to find</param>
|
|
/// <returns>The number of bytes read</returns>
|
|
internal static long FindSignature(System.IO.Stream stream, int SignatureToFind)
|
|
{
|
|
long startingPosition = stream.Position;
|
|
|
|
int BATCH_SIZE = 65536; // 8192;
|
|
byte[] targetBytes = new byte[4];
|
|
targetBytes[0] = (byte)(SignatureToFind >> 24);
|
|
targetBytes[1] = (byte)((SignatureToFind & 0x00FF0000) >> 16);
|
|
targetBytes[2] = (byte)((SignatureToFind & 0x0000FF00) >> 8);
|
|
targetBytes[3] = (byte)(SignatureToFind & 0x000000FF);
|
|
byte[] batch = new byte[BATCH_SIZE];
|
|
int n = 0;
|
|
bool success = false;
|
|
do
|
|
{
|
|
n = stream.Read(batch, 0, batch.Length);
|
|
if (n != 0)
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
if (batch[i] == targetBytes[3])
|
|
{
|
|
long curPosition = stream.Position;
|
|
stream.Seek(i - n, System.IO.SeekOrigin.Current);
|
|
// workitem 10178
|
|
Workaround_Ladybug318918(stream);
|
|
|
|
// workitem 7711
|
|
int sig = ReadSignature(stream);
|
|
|
|
success = (sig == SignatureToFind);
|
|
if (!success)
|
|
{
|
|
stream.Seek(curPosition, System.IO.SeekOrigin.Begin);
|
|
// workitem 10178
|
|
Workaround_Ladybug318918(stream);
|
|
}
|
|
else
|
|
break; // out of for loop
|
|
}
|
|
}
|
|
}
|
|
else break;
|
|
if (success) break;
|
|
|
|
} while (true);
|
|
|
|
if (!success)
|
|
{
|
|
stream.Seek(startingPosition, System.IO.SeekOrigin.Begin);
|
|
// workitem 10178
|
|
Workaround_Ladybug318918(stream);
|
|
return -1; // or throw?
|
|
}
|
|
|
|
// subtract 4 for the signature.
|
|
long bytesRead = (stream.Position - startingPosition) - 4;
|
|
|
|
return bytesRead;
|
|
}
|
|
|
|
|
|
// If I have a time in the .NET environment, and I want to use it for
|
|
// SetWastWriteTime() etc, then I need to adjust it for Win32.
|
|
internal static DateTime AdjustTime_Reverse(DateTime time)
|
|
{
|
|
if (time.Kind == DateTimeKind.Utc) return time;
|
|
DateTime adjusted = time;
|
|
if (DateTime.Now.IsDaylightSavingTime() && !time.IsDaylightSavingTime())
|
|
adjusted = time - new System.TimeSpan(1, 0, 0);
|
|
|
|
else if (!DateTime.Now.IsDaylightSavingTime() && time.IsDaylightSavingTime())
|
|
adjusted = time + new System.TimeSpan(1, 0, 0);
|
|
|
|
return adjusted;
|
|
}
|
|
|
|
#if NECESSARY
|
|
// If I read a time from a file with GetLastWriteTime() (etc), I need
|
|
// to adjust it for display in the .NET environment.
|
|
internal static DateTime AdjustTime_Forward(DateTime time)
|
|
{
|
|
if (time.Kind == DateTimeKind.Utc) return time;
|
|
DateTime adjusted = time;
|
|
if (DateTime.Now.IsDaylightSavingTime() && !time.IsDaylightSavingTime())
|
|
adjusted = time + new System.TimeSpan(1, 0, 0);
|
|
|
|
else if (!DateTime.Now.IsDaylightSavingTime() && time.IsDaylightSavingTime())
|
|
adjusted = time - new System.TimeSpan(1, 0, 0);
|
|
|
|
return adjusted;
|
|
}
|
|
#endif
|
|
|
|
|
|
internal static DateTime PackedToDateTime(Int32 packedDateTime)
|
|
{
|
|
// workitem 7074 & workitem 7170
|
|
if (packedDateTime == 0xFFFF || packedDateTime == 0)
|
|
return new System.DateTime(1995, 1, 1, 0, 0, 0, 0); // return a fixed date when none is supplied.
|
|
|
|
Int16 packedTime = unchecked((Int16)(packedDateTime & 0x0000ffff));
|
|
Int16 packedDate = unchecked((Int16)((packedDateTime & 0xffff0000) >> 16));
|
|
|
|
int year = 1980 + ((packedDate & 0xFE00) >> 9);
|
|
int month = (packedDate & 0x01E0) >> 5;
|
|
int day = packedDate & 0x001F;
|
|
|
|
int hour = (packedTime & 0xF800) >> 11;
|
|
int minute = (packedTime & 0x07E0) >> 5;
|
|
//int second = packedTime & 0x001F;
|
|
int second = (packedTime & 0x001F) * 2;
|
|
|
|
// validation and error checking.
|
|
// this is not foolproof but will catch most errors.
|
|
if (second >= 60) { minute++; second = 0; }
|
|
if (minute >= 60) { hour++; minute = 0; }
|
|
if (hour >= 24) { day++; hour = 0; }
|
|
|
|
DateTime d = System.DateTime.Now;
|
|
bool success= false;
|
|
try
|
|
{
|
|
d = new System.DateTime(year, month, day, hour, minute, second, 0);
|
|
success= true;
|
|
}
|
|
catch (System.ArgumentOutOfRangeException)
|
|
{
|
|
if (year == 1980 && (month == 0 || day == 0))
|
|
{
|
|
try
|
|
{
|
|
d = new System.DateTime(1980, 1, 1, hour, minute, second, 0);
|
|
success= true;
|
|
}
|
|
catch (System.ArgumentOutOfRangeException)
|
|
{
|
|
try
|
|
{
|
|
d = new System.DateTime(1980, 1, 1, 0, 0, 0, 0);
|
|
success= true;
|
|
}
|
|
catch (System.ArgumentOutOfRangeException) { }
|
|
|
|
}
|
|
}
|
|
// workitem 8814
|
|
// my god, I can't believe how many different ways applications
|
|
// can mess up a simple date format.
|
|
else
|
|
{
|
|
try
|
|
{
|
|
while (year < 1980) year++;
|
|
while (year > 2030) year--;
|
|
while (month < 1) month++;
|
|
while (month > 12) month--;
|
|
while (day < 1) day++;
|
|
while (day > 28) day--;
|
|
while (minute < 0) minute++;
|
|
while (minute > 59) minute--;
|
|
while (second < 0) second++;
|
|
while (second > 59) second--;
|
|
d = new System.DateTime(year, month, day, hour, minute, second, 0);
|
|
success= true;
|
|
}
|
|
catch (System.ArgumentOutOfRangeException) { }
|
|
}
|
|
}
|
|
if (!success)
|
|
{
|
|
string msg = String.Format("y({0}) m({1}) d({2}) h({3}) m({4}) s({5})", year, month, day, hour, minute, second);
|
|
throw new ZipException(String.Format("Bad date/time format in the zip file. ({0})", msg));
|
|
|
|
}
|
|
// workitem 6191
|
|
//d = AdjustTime_Reverse(d);
|
|
d = DateTime.SpecifyKind(d, DateTimeKind.Local);
|
|
return d;
|
|
}
|
|
|
|
|
|
internal
|
|
static Int32 DateTimeToPacked(DateTime time)
|
|
{
|
|
// The time is passed in here only for purposes of writing LastModified to the
|
|
// zip archive. It should always be LocalTime, but we convert anyway. And,
|
|
// since the time is being written out, it needs to be adjusted.
|
|
|
|
time = time.ToLocalTime();
|
|
// workitem 7966
|
|
//time = AdjustTime_Forward(time);
|
|
|
|
// see http://www.vsft.com/hal/dostime.htm for the format
|
|
UInt16 packedDate = (UInt16)((time.Day & 0x0000001F) | ((time.Month << 5) & 0x000001E0) | (((time.Year - 1980) << 9) & 0x0000FE00));
|
|
UInt16 packedTime = (UInt16)((time.Second / 2 & 0x0000001F) | ((time.Minute << 5) & 0x000007E0) | ((time.Hour << 11) & 0x0000F800));
|
|
|
|
Int32 result = (Int32)(((UInt32)(packedDate << 16)) | packedTime);
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Create a pseudo-random filename, suitable for use as a temporary
|
|
/// file, and open it.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The System.IO.Path.GetRandomFileName() method is not available on
|
|
/// the Compact Framework, so this library provides its own substitute
|
|
/// on NETCF.
|
|
/// </para>
|
|
/// <para>
|
|
/// This method produces a filename of the form
|
|
/// DotNetZip-xxxxxxxx.tmp, where xxxxxxxx is replaced by randomly
|
|
/// chosen characters, and creates that file.
|
|
/// </para>
|
|
/// </remarks>
|
|
public static void CreateAndOpenUniqueTempFile(string dir,
|
|
out Stream fs,
|
|
out string filename)
|
|
{
|
|
// workitem 9763
|
|
// http://dotnet.org.za/markn/archive/2006/04/15/51594.aspx
|
|
// try 3 times:
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
try
|
|
{
|
|
filename = Path.Combine(dir, InternalGetTempFileName());
|
|
fs = new FileStream(filename, FileMode.CreateNew);
|
|
return;
|
|
}
|
|
catch (IOException)
|
|
{
|
|
if (i == 2) throw;
|
|
}
|
|
}
|
|
throw new IOException();
|
|
}
|
|
|
|
#if NETCF || SILVERLIGHT
|
|
public static string InternalGetTempFileName()
|
|
{
|
|
return "DotNetZip-" + GenerateRandomStringImpl(8,0) + ".tmp";
|
|
}
|
|
|
|
internal static string GenerateRandomStringImpl(int length, int delta)
|
|
{
|
|
bool WantMixedCase = (delta == 0);
|
|
System.Random rnd = new System.Random();
|
|
|
|
string result = "";
|
|
char[] a = new char[length];
|
|
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
// delta == 65 means uppercase
|
|
// delta == 97 means lowercase
|
|
if (WantMixedCase)
|
|
delta = (rnd.Next(2) == 0) ? 65 : 97;
|
|
a[i] = (char)(rnd.Next(26) + delta);
|
|
}
|
|
|
|
result = new System.String(a);
|
|
return result;
|
|
}
|
|
#else
|
|
public static string InternalGetTempFileName()
|
|
{
|
|
return "DotNetZip-" + Path.GetRandomFileName().Substring(0, 8) + ".tmp";
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
/// <summary>
|
|
/// Workitem 7889: handle ERROR_LOCK_VIOLATION during read
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This could be gracefully handled with an extension attribute, but
|
|
/// This assembly is built for .NET 2.0, so I cannot use them.
|
|
/// </remarks>
|
|
internal static int ReadWithRetry(System.IO.Stream s, byte[] buffer, int offset, int count, string FileName)
|
|
{
|
|
int n = 0;
|
|
bool done = false;
|
|
#if !NETCF && !SILVERLIGHT
|
|
int retries = 0;
|
|
#endif
|
|
do
|
|
{
|
|
try
|
|
{
|
|
n = s.Read(buffer, offset, count);
|
|
done = true;
|
|
}
|
|
#if NETCF || SILVERLIGHT
|
|
catch (System.IO.IOException)
|
|
{
|
|
throw;
|
|
}
|
|
#else
|
|
catch (System.IO.IOException ioexc1)
|
|
{
|
|
// Check if we can call GetHRForException,
|
|
// which makes unmanaged code calls.
|
|
#if NET_CORE
|
|
bool bIsUnrestricted = true;
|
|
#else
|
|
var p = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
|
|
bool bIsUnrestricted = p.IsUnrestricted();
|
|
#endif
|
|
|
|
if (bIsUnrestricted)
|
|
{
|
|
uint hresult = _HRForException(ioexc1);
|
|
if (hresult != 0x80070021) // ERROR_LOCK_VIOLATION
|
|
throw new System.IO.IOException(String.Format("Cannot read file {0}", FileName), ioexc1);
|
|
retries++;
|
|
if (retries > 10)
|
|
throw new System.IO.IOException(String.Format("Cannot read file {0}, at offset 0x{1:X8} after 10 retries", FileName, offset), ioexc1);
|
|
|
|
// max time waited on last retry = 250 + 10*550 = 5.75s
|
|
// aggregate time waited after 10 retries: 250 + 55*550 = 30.5s
|
|
System.Threading.Thread.Sleep(250 + retries * 550);
|
|
}
|
|
else
|
|
{
|
|
// The permission.Demand() failed. Therefore, we cannot call
|
|
// GetHRForException, and cannot do the subtle handling of
|
|
// ERROR_LOCK_VIOLATION. Just bail.
|
|
throw;
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
while (!done);
|
|
|
|
return n;
|
|
}
|
|
|
|
|
|
#if !NETCF
|
|
// workitem 8009
|
|
//
|
|
// This method must remain separate.
|
|
//
|
|
// Marshal.GetHRForException() is needed to do special exception handling for
|
|
// the read. But, that method requires UnmanagedCode permissions, and is marked
|
|
// with LinkDemand for UnmanagedCode. In an ASP.NET medium trust environment,
|
|
// where UnmanagedCode is restricted, will generate a SecurityException at the
|
|
// time of JIT of the method that calls a method that is marked with LinkDemand
|
|
// for UnmanagedCode. The SecurityException, if it is restricted, will occur
|
|
// when this method is JITed.
|
|
//
|
|
// The Marshal.GetHRForException() is factored out of ReadWithRetry in order to
|
|
// avoid the SecurityException at JIT compile time. Because _HRForException is
|
|
// called only when the UnmanagedCode is allowed. This means .NET never
|
|
// JIT-compiles this method when UnmanagedCode is disallowed, and thus never
|
|
// generates the JIT-compile time exception.
|
|
//
|
|
#endif
|
|
private static uint _HRForException(System.Exception ex1)
|
|
{
|
|
return unchecked((uint)System.Runtime.InteropServices.Marshal.GetHRForException(ex1));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// A decorator stream. It wraps another stream, and performs bookkeeping
|
|
/// to keep track of the stream Position.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// In some cases, it is not possible to get the Position of a stream, let's
|
|
/// say, on a write-only output stream like ASP.NET's
|
|
/// <c>Response.OutputStream</c>, or on a different write-only stream
|
|
/// provided as the destination for the zip by the application. In this
|
|
/// case, programmers can use this counting stream to count the bytes read
|
|
/// or written.
|
|
/// </para>
|
|
/// <para>
|
|
/// Consider the scenario of an application that saves a self-extracting
|
|
/// archive (SFX), that uses a custom SFX stub.
|
|
/// </para>
|
|
/// <para>
|
|
/// Saving to a filesystem file, the application would open the
|
|
/// filesystem file (getting a <c>FileStream</c>), save the custom sfx stub
|
|
/// into it, and then call <c>ZipFile.Save()</c>, specifying the same
|
|
/// FileStream. <c>ZipFile.Save()</c> does the right thing for the zipentry
|
|
/// offsets, by inquiring the Position of the <c>FileStream</c> before writing
|
|
/// any data, and then adding that initial offset into any ZipEntry
|
|
/// offsets in the zip directory. Everything works fine.
|
|
/// </para>
|
|
/// <para>
|
|
/// Now suppose the application is an ASPNET application and it saves
|
|
/// directly to <c>Response.OutputStream</c>. It's not possible for DotNetZip to
|
|
/// inquire the <c>Position</c>, so the offsets for the SFX will be wrong.
|
|
/// </para>
|
|
/// <para>
|
|
/// The workaround is for the application to use this class to wrap
|
|
/// <c>HttpResponse.OutputStream</c>, then write the SFX stub and the ZipFile
|
|
/// into that wrapper stream. Because <c>ZipFile.Save()</c> can inquire the
|
|
/// <c>Position</c>, it will then do the right thing with the offsets.
|
|
/// </para>
|
|
/// </remarks>
|
|
public class CountingStream : System.IO.Stream
|
|
{
|
|
// workitem 12374: this class is now public
|
|
private System.IO.Stream _s;
|
|
private Int64 _bytesWritten;
|
|
private Int64 _bytesRead;
|
|
private Int64 _initialOffset;
|
|
|
|
/// <summary>
|
|
/// The constructor.
|
|
/// </summary>
|
|
/// <param name="stream">The underlying stream</param>
|
|
public CountingStream(System.IO.Stream stream)
|
|
: base()
|
|
{
|
|
_s = stream;
|
|
try
|
|
{
|
|
_initialOffset = _s.Position;
|
|
}
|
|
catch
|
|
{
|
|
_initialOffset = 0L;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the wrapped stream.
|
|
/// </summary>
|
|
public Stream WrappedStream
|
|
{
|
|
get
|
|
{
|
|
return _s;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The count of bytes written out to the stream.
|
|
/// </summary>
|
|
public Int64 BytesWritten
|
|
{
|
|
get { return _bytesWritten; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// the count of bytes that have been read from the stream.
|
|
/// </summary>
|
|
public Int64 BytesRead
|
|
{
|
|
get { return _bytesRead; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adjust the byte count on the stream.
|
|
/// </summary>
|
|
///
|
|
/// <param name='delta'>
|
|
/// the number of bytes to subtract from the count.
|
|
/// </param>
|
|
///
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Subtract delta from the count of bytes written to the stream.
|
|
/// This is necessary when seeking back, and writing additional data,
|
|
/// as happens in some cases when saving Zip files.
|
|
/// </para>
|
|
/// </remarks>
|
|
public void Adjust(Int64 delta)
|
|
{
|
|
_bytesWritten -= delta;
|
|
if (_bytesWritten < 0)
|
|
throw new InvalidOperationException();
|
|
if (_s as CountingStream != null)
|
|
((CountingStream)_s).Adjust(delta);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The read method.
|
|
/// </summary>
|
|
/// <param name="buffer">The buffer to hold the data read from the stream.</param>
|
|
/// <param name="offset">the offset within the buffer to copy the first byte read.</param>
|
|
/// <param name="count">the number of bytes to read.</param>
|
|
/// <returns>the number of bytes read, after decryption and decompression.</returns>
|
|
public override int Read(byte[] buffer, int offset, int count)
|
|
{
|
|
int n = _s.Read(buffer, offset, count);
|
|
_bytesRead += n;
|
|
return n;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Write data into the stream.
|
|
/// </summary>
|
|
/// <param name="buffer">The buffer holding data to write to the stream.</param>
|
|
/// <param name="offset">the offset within that data array to find the first byte to write.</param>
|
|
/// <param name="count">the number of bytes to write.</param>
|
|
public override void Write(byte[] buffer, int offset, int count)
|
|
{
|
|
if (count == 0) return;
|
|
_s.Write(buffer, offset, count);
|
|
_bytesWritten += count;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether the stream can be read.
|
|
/// </summary>
|
|
public override bool CanRead
|
|
{
|
|
get { return _s.CanRead; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether it is possible to call Seek() on the stream.
|
|
/// </summary>
|
|
public override bool CanSeek
|
|
{
|
|
get { return _s.CanSeek; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether it is possible to call Write() on the stream.
|
|
/// </summary>
|
|
public override bool CanWrite
|
|
{
|
|
get { return _s.CanWrite; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Flushes the underlying stream.
|
|
/// </summary>
|
|
public override void Flush()
|
|
{
|
|
_s.Flush();
|
|
}
|
|
|
|
/// <summary>
|
|
/// The length of the underlying stream.
|
|
/// </summary>
|
|
public override long Length
|
|
{
|
|
get { return _s.Length; } // bytesWritten??
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the sum of number of bytes written, plus the initial
|
|
/// offset before writing.
|
|
/// </summary>
|
|
public long ComputedPosition
|
|
{
|
|
get { return _initialOffset + _bytesWritten; }
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// The Position of the stream.
|
|
/// </summary>
|
|
public override long Position
|
|
{
|
|
get { return _s.Position; }
|
|
set
|
|
{
|
|
_s.Seek(value, System.IO.SeekOrigin.Begin);
|
|
// workitem 10178
|
|
Ionic.Zip.SharedUtilities.Workaround_Ladybug318918(_s);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Seek in the stream.
|
|
/// </summary>
|
|
/// <param name="offset">the offset point to seek to</param>
|
|
/// <param name="origin">the reference point from which to seek</param>
|
|
/// <returns>The new position</returns>
|
|
public override long Seek(long offset, System.IO.SeekOrigin origin)
|
|
{
|
|
return _s.Seek(offset, origin);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the length of the underlying stream. Be careful with this!
|
|
/// </summary>
|
|
///
|
|
/// <param name='value'>the length to set on the underlying stream.</param>
|
|
public override void SetLength(long value)
|
|
{
|
|
_s.SetLength(value);
|
|
}
|
|
}
|
|
|
|
|
|
}
|