SevenZip/SevenZipCompressor.cs
/// <summary>
///   Makes special FileInfo array for the archive file table.
/// </summary>
/// <param name = "files">Array of files to pack.</param>
/// <param name = "commonRootLength">The length of the common root of file names</param>
/// <param name = "directoryCompress">The value indicating whether to produce the array for files in a particular directory or just for an array of files.</param>
/// <param name = "directoryStructure">Preserve directory structure.</param>
/// <returns>Special FileInfo array for the archive file table.</returns>
Makes special FileInfo array for the archive file table.
Makes special FileInfo array for the archive file table .
private static FileInfo[] ProduceFileInfoArray(
            string[] files, int commonRootLength,
            bool directoryCompress, bool directoryStructure)
        {
            var fis = new List<FileInfo>(files.Length);
            string commonRoot = files[0].Substring(0, commonRootLength);
            if (directoryCompress)
            {
#if CS4
                fis.AddRange(files.Select(fn => new FileInfo(fn)));
#else
                foreach (string fn in files)
                {
                    fis.Add(new FileInfo(fn));
                }
#endif
            }
            else
            {
                if (!directoryStructure)
                {
#if CS4
                    fis.AddRange(from fn in files where !Directory.Exists(fn) select new FileInfo(fn));
#else
                    foreach (string fn in files)
                    {
                        if (!Directory.Exists(fn))
                        {
                            fis.Add(new FileInfo(fn));
                        }
                    }
#endif
                }
                else
                {
                    var fns = new List<string>(files.Length);
                    CheckCommonRoot(files, ref commonRootLength);
                    if (commonRootLength > 0)
                    {
                        commonRootLength++;
                        foreach (string f in files)
                        {
                            string[] splittedAfn = f.Substring(commonRootLength).Split(Path.DirectorySeparatorChar);
                            string cfn = commonRoot;
                            foreach (string t in splittedAfn)
                            {
                                cfn += Path.DirectorySeparatorChar + t;
                                if (!fns.Contains(cfn))
                                {
                                    fis.Add(new FileInfo(cfn));
                                    fns.Add(cfn);
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (string f in files)
                        {
                            string[] splittedAfn = f.Substring(commonRootLength).Split(Path.DirectorySeparatorChar);
                            string cfn = splittedAfn[0];
                            for (int i = 1; i < splittedAfn.Length; i++)
                            {
                                cfn += Path.DirectorySeparatorChar + splittedAfn[i];
                                if (!fns.Contains(cfn))
                                {
                                    fis.Add(new FileInfo(cfn));
                                    fns.Add(cfn);
                                }
                            }
                        }
                    }
                }
            }
            return fis.ToArray();
        }
private static FileInfo [ ] ProduceFileInfoArray ( string [ ] files , int commonRootLength , bool directoryCompress , bool directoryStructure ) { var fis = new List < FileInfo > ( files . Length ) ; string commonRoot = files [ 0 ] . Substring ( 0 , commonRootLength ) ; if ( directoryCompress ) { if CS4 fis . AddRange ( files . Select ( fn => new FileInfo ( fn ) ) ) ; else foreach ( string fn in files ) { fis . Add ( new FileInfo ( fn ) ) ; } endif } else { if ( ! directoryStructure ) { if CS4 fis . AddRange ( from fn in files where ! Directory . Exists ( fn ) select new FileInfo ( fn ) ) ; else foreach ( string fn in files ) { if ( ! Directory . Exists ( fn ) ) { fis . Add ( new FileInfo ( fn ) ) ; } } endif } else { var fns = new List < string > ( files . Length ) ; CheckCommonRoot ( files , ref commonRootLength ) ; if ( commonRootLength > 0 ) { commonRootLength ++ ; foreach ( string f in files ) { string [ ] splittedAfn = f . Substring ( commonRootLength ) . Split ( Path . DirectorySeparatorChar ) ; string cfn = commonRoot ; foreach ( string t in splittedAfn ) { cfn += Path . DirectorySeparatorChar + t ; if ( ! fns . Contains ( cfn ) ) { fis . Add ( new FileInfo ( cfn ) ) ; fns . Add ( cfn ) ; } } } } else { foreach ( string f in files ) { string [ ] splittedAfn = f . Substring ( commonRootLength ) . Split ( Path . DirectorySeparatorChar ) ; string cfn = splittedAfn [ 0 ] ; for ( int i = 1 ; i < splittedAfn . Length ; i ++ ) { cfn += Path . DirectorySeparatorChar + splittedAfn [ i ] ; if ( ! fns . Contains ( cfn ) ) { fis . Add ( new FileInfo ( cfn ) ) ; fns . Add ( cfn ) ; } } } } } } return fis . ToArray ( ) ; }
Makes special FileInfo array for the archive file table.
Makes special FileInfo array for the archive file table .
Special FileInfo array for the archive file table.
Special FileInfo array for the archive file table .
files
string[]
Array of files to pack.
Array of files to pack .
commonRootLength
int
The length of the common root of file names
The length of the common root of file names
directoryCompress
bool
The value indicating whether to produce the array for files in a particular directory or just for an array of files.
The value indicating whether to produce the array for files in a particular directory or just for an array of files .
directoryStructure
bool
Preserve directory structure.
Preserve directory structure .