コード例 #1
0
 internal BuildFileInfo(string name, BuildDirectoryInfo parent, byte[] content)
     : base(IsoUtilities.NormalizeFileName(name), MakeShortFileName(name, parent))
 {
     _parent      = parent;
     _contentData = content;
     _contentSize = content.LongLength;
 }
コード例 #2
0
 internal BuildFileInfo(string name, BuildDirectoryInfo parent, Stream source)
     : base(IsoUtilities.NormalizeFileName(name), MakeShortFileName(name, parent))
 {
     _parent        = parent;
     _contentStream = source;
     _contentSize   = _contentStream.Length;
 }
コード例 #3
0
        private static string MakeShortFileName(string longName, BuildDirectoryInfo dir)
        {
            if (IsoUtilities.IsValidFileName(longName))
            {
                return(longName);
            }

            char[] shortNameChars = longName.ToUpper(CultureInfo.InvariantCulture).ToCharArray();
            for (int i = 0; i < shortNameChars.Length; ++i)
            {
                if (!IsoUtilities.IsValidDChar(shortNameChars[i]) && shortNameChars[i] != '.' &&
                    shortNameChars[i] != ';')
                {
                    shortNameChars[i] = '_';
                }
            }

            string[] parts = IsoUtilities.SplitFileName(new string(shortNameChars));

            if (parts[0].Length + parts[1].Length > 30)
            {
                parts[1] = parts[1].Substring(0, Math.Min(parts[1].Length, 3));
            }

            if (parts[0].Length + parts[1].Length > 30)
            {
                parts[0] = parts[0].Substring(0, 30 - parts[1].Length);
            }

            string candidate = parts[0] + '.' + parts[1] + ';' + parts[2];

            // TODO: Make unique
            return(candidate);
        }
コード例 #4
0
 internal BuildDirectoryInfo(string name, BuildDirectoryInfo parent)
     : base(name, MakeShortDirName(name, parent))
 {
     _parent         = (parent == null) ? this : parent;
     _hierarchyDepth = (parent == null) ? 0 : parent._hierarchyDepth + 1;
     _members        = new Dictionary <string, BuildDirectoryMember>();
 }
コード例 #5
0
ファイル: DirectoryExtent.cs プロジェクト: lanicon/Commander
 public DirectoryExtent(BuildDirectoryInfo dirInfo, Dictionary <BuildDirectoryMember, uint> locationTable,
                        Encoding enc, long start)
     : base(start, dirInfo.GetDataSize(enc))
 {
     _dirInfo       = dirInfo;
     _locationTable = locationTable;
     _enc           = enc;
 }
コード例 #6
0
        internal BuildFileInfo(string name, BuildDirectoryInfo parent, string content)
            : base(IsoUtilities.NormalizeFileName(name), MakeShortFileName(name, parent))
        {
            _parent      = parent;
            _contentPath = content;
            _contentSize = new FileInfo(_contentPath).Length;

            CreationTime = new FileInfo(_contentPath).LastWriteTimeUtc;
        }
コード例 #7
0
ファイル: CDBuilder.cs プロジェクト: lanicon/Commander
        /// <summary>
        /// Initializes a new instance of the CDBuilder class.
        /// </summary>
        public CDBuilder()
        {
            _files         = new List <BuildFileInfo>();
            _dirs          = new List <BuildDirectoryInfo>();
            _rootDirectory = new BuildDirectoryInfo("\0", null);
            _dirs.Add(_rootDirectory);

            _buildParams           = new BuildParameters();
            _buildParams.UseJoliet = true;
        }
コード例 #8
0
ファイル: CDBuilder.cs プロジェクト: lanicon/Commander
        private BuildDirectoryInfo GetDirectory(string[] path, int pathLength, bool createMissing)
        {
            BuildDirectoryInfo di = TryGetDirectory(path, pathLength, createMissing);

            if (di == null)
            {
                throw new DirectoryNotFoundException("Directory not found");
            }

            return(di);
        }
コード例 #9
0
ファイル: CDBuilder.cs プロジェクト: lanicon/Commander
        /// <summary>
        /// Adds a disk file to the ISO image as a file.
        /// </summary>
        /// <param name="name">The name of the file on the ISO image.</param>
        /// <param name="sourcePath">The name of the file on disk.</param>
        /// <returns>The object representing this file.</returns>
        /// <remarks>
        /// The name is the full path to the file, for example:
        /// <example><code>
        ///   builder.AddFile(@"DIRA\DIRB\FILE.TXT;1", @"C:\temp\tempfile.bin");
        /// </code></example>
        /// <para>Note the version number at the end of the file name is optional, if not
        /// specified the default of 1 will be used.</para>
        /// </remarks>
        public BuildFileInfo AddFile(string name, string sourcePath)
        {
            string[]           nameElements = name.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            BuildDirectoryInfo dir          = GetDirectory(nameElements, nameElements.Length - 1, true);

            BuildDirectoryMember existing;

            if (dir.TryGetMember(nameElements[nameElements.Length - 1], out existing))
            {
                throw new IOException("File already exists");
            }
            else
            {
                BuildFileInfo fi = new BuildFileInfo(nameElements[nameElements.Length - 1], dir, sourcePath);
                _files.Add(fi);
                dir.Add(fi);
                return(fi);
            }
        }
コード例 #10
0
        private static string MakeShortDirName(string longName, BuildDirectoryInfo dir)
        {
            if (IsoUtilities.IsValidDirectoryName(longName))
            {
                return(longName);
            }

            char[] shortNameChars = longName.ToUpper(CultureInfo.InvariantCulture).ToCharArray();
            for (int i = 0; i < shortNameChars.Length; ++i)
            {
                if (!IsoUtilities.IsValidDChar(shortNameChars[i]) && shortNameChars[i] != '.' &&
                    shortNameChars[i] != ';')
                {
                    shortNameChars[i] = '_';
                }
            }

            return(new string(shortNameChars));
        }
コード例 #11
0
ファイル: CDBuilder.cs プロジェクト: lanicon/Commander
        private BuildDirectoryInfo TryGetDirectory(string[] path, int pathLength, bool createMissing)
        {
            BuildDirectoryInfo focus = _rootDirectory;

            for (int i = 0; i < pathLength; ++i)
            {
                BuildDirectoryMember next;
                if (!focus.TryGetMember(path[i], out next))
                {
                    if (createMissing)
                    {
                        // This directory doesn't exist, create it...
                        BuildDirectoryInfo di = new BuildDirectoryInfo(path[i], focus);
                        focus.Add(di);
                        _dirs.Add(di);
                        focus = di;
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    BuildDirectoryInfo nextAsBuildDirectoryInfo = next as BuildDirectoryInfo;
                    if (nextAsBuildDirectoryInfo == null)
                    {
                        throw new IOException("File with conflicting name exists");
                    }
                    else
                    {
                        focus = nextAsBuildDirectoryInfo;
                    }
                }
            }

            return(focus);
        }
コード例 #12
0
ファイル: CDBuilder.cs プロジェクト: lanicon/Commander
        /// <summary>
        /// Adds a stream to the ISO image as a file.
        /// </summary>
        /// <param name="name">The name of the file on the ISO image.</param>
        /// <param name="source">The contents of the file.</param>
        /// <returns>The object representing this file.</returns>
        /// <remarks>
        /// The name is the full path to the file, for example:
        /// <example><code>
        ///   builder.AddFile(@"DIRA\DIRB\FILE.TXT;1", stream);
        /// </code></example>
        /// <para>Note the version number at the end of the file name is optional, if not
        /// specified the default of 1 will be used.</para>
        /// </remarks>
        public BuildFileInfo AddFile(string name, Stream source)
        {
            if (!source.CanSeek)
            {
                throw new ArgumentException("source doesn't support seeking", "source");
            }

            string[]           nameElements = name.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            BuildDirectoryInfo dir          = GetDirectory(nameElements, nameElements.Length - 1, true);

            BuildDirectoryMember existing;

            if (dir.TryGetMember(nameElements[nameElements.Length - 1], out existing))
            {
                throw new IOException("File already exists");
            }
            else
            {
                BuildFileInfo fi = new BuildFileInfo(nameElements[nameElements.Length - 1], dir, source);
                _files.Add(fi);
                dir.Add(fi);
                return(fi);
            }
        }