@@ -65,13 +65,13 @@ public bool Extract(Stream? stream, string file, string outDir, bool lookForHead
6565 return false ;
6666#endif
6767 }
68-
68+
6969#if NET462_OR_GREATER || NETCOREAPP
7070 /// <summary>
7171 /// Extraction method for non-solid archives. This iterates over each entry in the archive to extract every
7272 /// file individually, in order to extract all valid files from the archive.
7373 /// </summary>
74- private bool ExtractNonSolid ( SevenZipArchive sevenZip , string outDir , bool includeDebug )
74+ private static bool ExtractNonSolid ( SevenZipArchive sevenZip , string outDir , bool includeDebug )
7575 {
7676 foreach ( var entry in sevenZip . Entries )
7777 {
@@ -89,12 +89,20 @@ private bool ExtractNonSolid(SevenZipArchive sevenZip, string outDir, bool inclu
8989 if ( ! entry . IsComplete )
9090 continue ;
9191
92- string tempFile = Path . Combine ( outDir , entry . Key ) ;
93- var directoryName = Path . GetDirectoryName ( tempFile ) ;
92+ // Ensure directory separators are consistent
93+ string filename = entry . Key ;
94+ if ( Path . DirectorySeparatorChar == '\\ ' )
95+ filename = filename . Replace ( '/' , '\\ ' ) ;
96+ else if ( Path . DirectorySeparatorChar == '/' )
97+ filename = filename . Replace ( '\\ ' , '/' ) ;
98+
99+ // Ensure the full output directory exists
100+ filename = Path . Combine ( outDir , filename ) ;
101+ var directoryName = Path . GetDirectoryName ( filename ) ;
94102 if ( directoryName != null && ! Directory . Exists ( directoryName ) )
95103 Directory . CreateDirectory ( directoryName ) ;
96104
97- entry . WriteToFile ( tempFile ) ;
105+ entry . WriteToFile ( filename ) ;
98106 }
99107 catch ( Exception ex )
100108 {
@@ -103,24 +111,24 @@ private bool ExtractNonSolid(SevenZipArchive sevenZip, string outDir, bool inclu
103111 }
104112 return true ;
105113 }
106-
114+
107115 /// <summary>
108116 /// Extraction method for solid archives. Uses ExtractAllEntries because extraction for solid archives must be
109117 /// done sequentially, and files beyond a corrupted point in a solid archive will be unreadable anyways.
110118 /// </summary>
111- private bool ExtractSolid ( SevenZipArchive sevenZip , string outDir , bool includeDebug )
119+ private static bool ExtractSolid ( SevenZipArchive sevenZip , string outDir , bool includeDebug )
112120 {
113121 try
114122 {
115123 if ( ! Directory . Exists ( outDir ) )
116124 Directory . CreateDirectory ( outDir ) ;
117-
125+
118126 sevenZip . WriteToDirectory ( outDir , new ExtractionOptions ( )
119127 {
120128 ExtractFullPath = true ,
121- Overwrite = true ,
129+ Overwrite = true ,
122130 } ) ;
123-
131+
124132 }
125133 catch ( Exception ex )
126134 {
0 commit comments