Beispiel #1
0
        public IPackageManifest ReadManifest(Stream s)
        {
            XmlSerializer   xs = new XmlSerializer(typeof(PackageManifest));
            PackageManifest pm = (PackageManifest)xs.Deserialize(s);

            s.Close();
            return(pm);
        }
Beispiel #2
0
        public IPackageManifest GetPackageManifest(string path)
        {
            ZipArchive      pack = ZipFile.OpenRead(path);
            Stream          s    = pack.GetEntry(ManifestPath).Open();
            PackageManifest pm   = (PackageManifest)ReadManifest(s);

            pack.Dispose();
            return(pm);
        }
Beispiel #3
0
        private bool CheckHashes(PackageManifest pm, string outPutDir)
        {
            string[] files     = Directory.GetFiles(outPutDir, "*", SearchOption.AllDirectories);
            Uri      outDir    = new Uri(Path.GetFullPath(outPutDir));
            bool     isCorrect = true;

            for (int j = 0; j < files.Length; j++)
            {
                string f = new Uri(Path.GetFullPath(files[j])).MakeRelativeUri(outDir).ToString();
                for (int i = 0; i < pm.Hashes.Count; i++)
                {
                    if (f == pm.Hashes[i].File)
                    {
                        Stream s = File.OpenRead(files[i]);
                        isCorrect &= CompareHash(pm.Hashes[i].Hash, s);
                        s.Close();
                    }
                }
            }

            return(isCorrect);
        }
Beispiel #4
0
        public void CreateEnginePackage(string outputFile, string workingDir, string[] files, string version = null)
        {
            File.WriteAllBytes(outputFile,
                               new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
            FileStream fs = new FileStream(outputFile, FileMode.Open);

            ZipArchive a        = new ZipArchive(fs, ZipArchiveMode.Update);
            Uri        wdir     = new Uri(workingDir);
            string     wdirname = Path.GetFileName(workingDir);

            if (string.IsNullOrEmpty(version))
            {
                version = Creator.GetEngineVersion(workingDir);
            }

            List <HashEntry> entries = new List <HashEntry>();
            PackageManifest  pm      = new PackageManifest("Engine", "", version, entries);

            foreach (string file in files)
            {
                Uri             f     = new Uri(file);
                string          fname = wdir.MakeRelativeUri(f).ToString().Remove(0, wdirname.Length + 1);
                ZipArchiveEntry e     = a.CreateEntry(fname);

                byte[] content = File.ReadAllBytes(file);
                entries.Add(CreateEntry(fname, content));
                Stream s = e.Open();
                s.Write(content, 0, content.Length);
                s.Close();
            }

            ZipArchiveEntry engVersion = a.CreateEntry(ManifestPath);
            Stream          str        = engVersion.Open();

            Creator.WriteManifest(str, pm);
            str.Close();
            a.Dispose();
            fs.Close();
        }