77using ICSharpCode . SharpZipLib . Core ;
88using ICSharpCode . SharpZipLib . Zip ;
99using log4net ;
10- using ChinhDo . Transactions . FileManager ;
10+ using ChinhDo . Transactions ;
1111
1212using CKAN . Extensions ;
1313using CKAN . Versioning ;
@@ -32,12 +32,13 @@ public ModuleInstaller(GameInstance inst,
3232 IUser user ,
3333 CancellationToken cancelToken = default )
3434 {
35- User = user ;
36- this . cache = cache ;
37- this . config = config ;
38- instance = inst ;
35+ log . DebugFormat ( "Creating ModuleInstaller for {0}" , inst . GameDir ) ;
36+ instance = inst ;
37+ // Make a transaction file manager that uses a temp dir in the instance's CKAN dir
38+ this . cache = cache ;
39+ this . config = config ;
40+ User = user ;
3941 this . cancelToken = cancelToken ;
40- log . DebugFormat ( "Creating ModuleInstaller for {0}" , instance . GameDir ) ;
4142 }
4243
4344 public IUser User { get ; set ; }
@@ -394,9 +395,9 @@ private List<string> InstallModule(CkanModule
394395 // Delete the manually installed DLL transaction-style because we believe we'll be replacing it
395396 var toDelete = instance . ToAbsoluteGameDir ( dll ) ;
396397 log . DebugFormat ( "Deleting manually installed DLL {0}" , toDelete ) ;
397- TxFileManager file_transaction = new TxFileManager ( ) ;
398- file_transaction . Snapshot ( toDelete ) ;
399- file_transaction . Delete ( toDelete ) ;
398+ var txFileMgr = new TxFileManager ( instance . CkanDir ) ;
399+ txFileMgr . Snapshot ( toDelete ) ;
400+ txFileMgr . Delete ( toDelete ) ;
400401 }
401402 }
402403
@@ -543,13 +544,13 @@ private static bool StreamsEqual(Stream s1, Stream s2)
543544 /// fails at a later stage.
544545 /// </summary>
545546 /// <param name="files">The files to overwrite</param>
546- private static void DeleteConflictingFiles( IEnumerable < InstallableFile > files )
547+ private void DeleteConflictingFiles( IEnumerable < InstallableFile > files )
547548 {
548- TxFileManager file_transaction = new TxFileManager( ) ;
549+ var txFileMgr = new TxFileManager( instance . CkanDir ) ;
549550 foreach ( InstallableFile file in files)
550551 {
551552 log. DebugFormat ( "Trying to delete {0}" , file . destination ) ;
552- file_transaction . Delete ( file . destination ) ;
553+ txFileMgr . Delete ( file . destination ) ;
553554 }
554555 }
555556
@@ -695,6 +696,16 @@ public static List<InstallableFile> FindInstallableFiles(CkanModule module,
695696
696697 #endregion
697698
699+ private string ? InstallFile ( ZipFile zipfile ,
700+ ZipEntry entry ,
701+ string fullPath ,
702+ bool makeDirs ,
703+ string [ ] candidateDuplicates ,
704+ IProgress < long > ? progress )
705+ => InstallFile ( zipfile , entry , fullPath , makeDirs ,
706+ new TxFileManager ( instance . CkanDir ) ,
707+ candidateDuplicates , progress ) ;
708+
698709 /// <summary>
699710 /// Copy the entry from the opened zipfile to the path specified.
700711 /// </summary>
@@ -707,11 +718,10 @@ public static List<InstallableFile> FindInstallableFiles(CkanModule module,
707718 ZipEntry entry ,
708719 string fullPath ,
709720 bool makeDirs ,
721+ IFileManager txFileMgr ,
710722 string [ ] candidateDuplicates ,
711723 IProgress < long > ? progress )
712724 {
713- var file_transaction = new TxFileManager( ) ;
714-
715725 if ( entry . IsDirectory )
716726 {
717727 // Skip if we're not making directories for this install.
@@ -727,7 +737,7 @@ public static List<InstallableFile> FindInstallableFiles(CkanModule module,
727737 : fullPath ;
728738
729739 log. DebugFormat ( "Making directory '{0}'" , fullPath ) ;
730- file_transaction . CreateDirectory ( fullPath ) ;
740+ txFileMgr . CreateDirectory ( fullPath ) ;
731741 }
732742 else
733743 {
@@ -737,19 +747,19 @@ public static List<InstallableFile> FindInstallableFiles(CkanModule module,
737747 if ( makeDirs && Path . GetDirectoryName ( fullPath ) is string d )
738748 {
739749 log. DebugFormat ( "Making parent directory '{0}'" , d ) ;
740- file_transaction . CreateDirectory ( d ) ;
750+ txFileMgr . CreateDirectory ( d ) ;
741751 }
742752
743753 // We don't allow for the overwriting of files. See #208.
744- if ( file_transaction . FileExists ( fullPath ) )
754+ if ( txFileMgr . FileExists ( fullPath ) )
745755 {
746756 throw new FileExistsKraken( fullPath ) ;
747757 }
748758
749759 // Snapshot whatever was there before. If there's nothing, this will just
750760 // remove our file on rollback. We still need this even though we won't
751761 // overwite files, as it ensures deletion on rollback.
752- file_transaction . Snapshot ( fullPath ) ;
762+ txFileMgr . Snapshot ( fullPath ) ;
753763
754764 // Try making hard links if already installed in another instance (faster, less space)
755765 foreach ( var installedSource in candidateDuplicates )
@@ -918,7 +928,7 @@ private void Uninstall(string identifier,
918928 Registry registry ,
919929 IProgress < long > progress )
920930 {
921- var file_transaction = new TxFileManager ( ) ;
931+ var txFileMgr = new TxFileManager( instance . CkanDir ) ;
922932
923933 using ( var transaction = CkanTransaction. CreateTransactionScope ( ) )
924934 {
@@ -972,7 +982,7 @@ private void Uninstall(string identifier,
972982 bytesDeleted += new FileInfo ( absPath ) . Length ;
973983 progress. Report ( bytesDeleted ) ;
974984 log. DebugFormat ( "Removing {0}" , relPath ) ;
975- file_transaction . Delete ( absPath ) ;
985+ txFileMgr . Delete ( absPath ) ;
976986 }
977987 }
978988 catch ( FileNotFoundException exc )
@@ -1044,7 +1054,7 @@ private void Uninstall(string identifier,
10441054 if ( File . Exists ( absPath ) )
10451055 {
10461056 log. DebugFormat ( "Attempting transaction deletion of file {0}" , absPath ) ;
1047- file_transaction . Delete ( absPath ) ;
1057+ txFileMgr . Delete ( absPath ) ;
10481058 }
10491059 else if ( Directory . Exists ( absPath ) )
10501060 {
@@ -1063,7 +1073,7 @@ private void Uninstall(string identifier,
10631073
10641074 if ( notRemovable . Length < 1 )
10651075 {
1066- // We *don't* use our file_transaction to delete files here, because
1076+ // We *don't* use our txFileMgr to delete files here, because
10671077 // it fails if the system's temp directory is on a different device
10681078 // to KSP. However we *can* safely delete it now we know it's empty,
10691079 // because the TxFileMgr *will* put it back if there's a file inside that
0 commit comments