コード例 #1
0
        /// <summary>
        /// Tries to create a pack.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="pack">The pack.</param>
        /// <returns></returns>
        public static bool TryCreatePack(TBLogFile project, out Pack pack)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            TBLogFile log = project;

            string projectDir = project.Project.Path;

            Pack p = new Pack();

            p.BaseDir = projectDir;

            PackContainer projectOutput = p.Containers.AddItem("#ProjectOutput");

            TBLogConfiguration config = log.Configurations[0];


            if (!string.IsNullOrEmpty(config.OutputPath))
            {
                projectOutput.ContainerDir = config.OutputPath;
                projectOutput.BaseDir      = config.OutputPath;
            }

            foreach (TBLogItem item in config.ProjectOutput.Items)
            {
                if (item.IsShared)
                {
                    continue;
                }

                PackFile pf = projectOutput.Files.AddItem(QQnPath.MakeRelativePath(projectOutput.BaseDir, QQnPath.Combine(projectDir, item.Src)));

                pf.StreamName = item.Src;
            }

            PackContainer projectContent = p.Containers.AddItem("#ProjectContent");

            if (!string.IsNullOrEmpty(config.OutputPath))
            {
                projectContent.ContainerDir = "content/" + log.Project.Name;
                projectContent.BaseDir      = log.ProjectPath;
            }

            foreach (TBLogItem item in config.Content.Items)
            {
                PackFile pf = projectContent.Files.AddItem(QQnPath.MakeRelativePath(projectContent.BaseDir, QQnPath.Combine(projectDir, item.Src)));

                pf.StreamName = item.Src;
            }

            PackContainer projectScripts = p.Containers.AddItem("#ProjectScripts");

            if (!string.IsNullOrEmpty(config.OutputPath))
            {
                projectScripts.ContainerDir = "scripts/" + log.Project.Name;
                projectScripts.BaseDir      = log.Project.Path;
            }

            foreach (TBLogItem item in config.Content.Items)
            {
                PackFile pf = projectContent.Files.AddItem(QQnPath.MakeRelativePath(projectContent.BaseDir, QQnPath.Combine(projectDir, item.Src)));

                pf.StreamName = item.Src;
            }

            if (config.Target.KeySrc != null)
            {
                p.StrongNameKey = StrongNameKey.LoadFrom(QQnPath.Combine(log.Project.Path, config.Target.KeySrc));
            }
            else if (config.Target.KeyContainer != null)
            {
                p.StrongNameKey = StrongNameKey.LoadFromContainer(config.Target.KeyContainer, false);
            }


            foreach (PackContainer pc in p.Containers)
            {
                foreach (PackFile pf in pc.Files)
                {
                    VerifyUtils.UpdateFile(pf.BaseDir, pf);
                }
            }

            pack = p;

            return(true);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackContainerCollection"/> class.
 /// </summary>
 /// <param name="pack">The pack.</param>
 protected internal PackContainerCollection(Pack pack)
     : base(pack)
 {
 }
コード例 #3
0
        /// <summary>
        /// Creates the specified package
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="definition">The definition.</param>
        /// <returns></returns>
        public static TPack Create(string fileName, Pack definition)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            AssuredStreamCreateArgs args = new AssuredStreamCreateArgs();

            if (definition.StrongNameKey != null)
            {
                args.StrongNameKey = definition.StrongNameKey;
            }

            args.FileType = PackageFileType;

            MultipleStreamCreateArgs msca = new MultipleStreamCreateArgs();

            msca.MaximumNumberOfStreams = 4;
            msca.VerificationMode       = VerificationMode.None;

            using (FileStream fs = File.Create(fileName, 65536))
                using (AssuredStream assurance = new AssuredStream(fs, args))
                    using (MultipleStreamWriter msw = new MultipleStreamWriter(assurance, msca))
                    {
                        MultipleStreamArgs msa = new MultipleStreamArgs();
                        msa.StreamType = 0x10;
                        msa.Assured    = true;
                        msa.GZipped    = true;
                        using (XmlWriter xw = new XmlTextWriter(msw.CreateStream(msa), Encoding.UTF8))
                        {
                            xw.WriteStartDocument();
                            xw.WriteStartElement("TurtlePackage", "http://schemas.qqn.nl/2007/TurtlePackage");
                            Tokenizer.TryWriteXml(xw, definition);
                            xw.WriteEndDocument();
                        }

                        msa            = new MultipleStreamArgs();
                        msa.StreamType = 0x11;

                        using (XmlWriter xw = new XmlTextWriter(msw.CreateStream(msa), Encoding.UTF8))
                        {
                            // TODO: Write tblog file
                        }


                        // Last stream: We add a zip file
                        msa            = new MultipleStreamArgs();
                        msa.StreamType = ZipFileId;  // Defined
                        msa.Assured    = false;      // Use the whole file assurance for the zip
                        msa.GZipped    = false;      // Don't compress again

                        using (Stream ms = msw.CreateStream(msa))
                            using (ZipFile zipFile = ZipFile.Create(ms))
                            {
                                zipFile.BeginUpdate();
                                zipFile.UseZip64 = UseZip64.Dynamic;

                                SetName setName = new SetName();

                                zipFile.NameTransform = setName;

                                SortedFileList added = new SortedFileList();
                                added.BaseDirectory = "c:\\" + Guid.NewGuid();

                                foreach (PackContainer container in definition.Containers)
                                {
                                    foreach (PackFile file in container.Files)
                                    {
                                        if (!QQnPath.IsRelativeSubPath(file.StreamName) || added.Contains(file.StreamName))
                                        {
                                            string name = Path.GetFileNameWithoutExtension(file.StreamName);
                                            string ext  = Path.GetExtension(file.StreamName);

                                            string attempt = "_/" + name + ext;
                                            int    n       = 0;
                                            do
                                            {
                                                if (!added.Contains(attempt))
                                                {
                                                    file.StreamName = attempt;
                                                    break;
                                                }

                                                attempt = string.Format("_/{0}.{1}.{2}", name, n++, ext);
                                            }while (true);
                                        }

                                        if (file.StreamName.Contains("\\"))
                                        {
                                            file.StreamName = file.StreamName.Replace('\\', '/');
                                        }

                                        added.Add(file.StreamName);
                                        setName.NextName = file.StreamName;

                                        zipFile.Add(file.FullName);
                                    }
                                }

                                zipFile.CommitUpdate();
                            }
                    }

            return(null);
        }