File size: 914 Bytes
fab29d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.IO;
using System.IO.Compression;

namespace VersOne.Epub.Environment.Implementation
{
    internal class FileSystem : IFileSystem
    {
#if NETFRAMEWORK
        private const int MAX_PATH = 260;
#endif

        public bool FileExists(string path)
        {
            return File.Exists(GetCompatibleFilePath(path));
        }

        public IZipFile OpenZipFile(string path)
        {
            return new ZipFile(System.IO.Compression.ZipFile.OpenRead(path));
        }

        public IZipFile OpenZipFile(Stream stream)
        {
            return new ZipFile(new ZipArchive(stream, ZipArchiveMode.Read));
        }

        private string GetCompatibleFilePath(string path)
        {
#if NETFRAMEWORK
            if (path.Length >= MAX_PATH && !path.StartsWith(@"\\?\"))
            {
                return @"\\?\" + path;
            }
#endif
            return path;
        }
    }
}