示例#1
0
        internal async Task Initialise()
        {
            StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(this._path);

            if (file == null)
            {
                throw new FileNotFoundException("the file could not be found in the isolated storage");
            }

            this.FullPath = file.Path;
            this._bundle  = ZipArchive.Open(await file.OpenStreamForReadAsync());

            var manifestEntry = this._bundle.Entries.Where(e => string.Compare(e.Key, "manifest.json", StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault();

            if (manifestEntry == null)
            {
                throw new ArgumentException("manifest.json not found in archive - not a Pebble this.Bundle.");
            }

            using (Stream jsonstream = manifestEntry.OpenEntryStream())
            {
                var serializer = new DataContractJsonSerializer(typeof(BundleManifest));
                this.Manifest = serializer.ReadObject(jsonstream) as BundleManifest;
            }

            if (this.Manifest.Type == "firmware")
            {
                this.BundleType    = BundleType.Firmware;
                this.BinaryContent = await this.ReadFileToArray(this.Manifest.Firmware.Filename, this.Manifest.Firmware.Size);
            }
            else
            {
                this.BundleType    = BundleType.Application;
                this.BinaryContent = await this.ReadFileToArray(this.Manifest.ApplicationManifest.Filename, this.Manifest.ApplicationManifest.Size);

                // Convert first part to app manifest
#if NETFX_CORE && !WINDOWS_PHONE_APP
                byte[] buffer = new byte[Marshal.SizeOf <ApplicationMetadata>()];
#else
                byte[] buffer = new byte[Marshal.SizeOf(typeof(ApplicationMetadata))];
#endif
                Array.Copy(this.BinaryContent, 0, buffer, 0, buffer.Length);
                this.Application = buffer.AsStruct <ApplicationMetadata>();
            }

            this.HasResources = this.Manifest.Resources.Size != 0;
            if (this.HasResources)
            {
                this.Resources = await this.ReadFileToArray(this.Manifest.Resources.Filename, this.Manifest.Resources.Size);
            }
        }
示例#2
0
        internal async Task Initialise()
        {
            StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(this._path);
            if (file == null)
            {
                throw new FileNotFoundException("the file could not be found in the isolated storage");
            }

            this.FullPath = file.Path;
            this._bundle = ZipArchive.Open(await file.OpenStreamForReadAsync());
           
            var manifestEntry = this._bundle.Entries.Where(e => string.Compare(e.Key, "manifest.json", StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault();
            if (manifestEntry == null)
            {
                throw new ArgumentException("manifest.json not found in archive - not a Pebble this.Bundle.");
            }

            using (Stream jsonstream = manifestEntry.OpenEntryStream())
            {
                var serializer = new DataContractJsonSerializer(typeof(BundleManifest));
                this.Manifest = serializer.ReadObject(jsonstream) as BundleManifest;
            }

            if (this.Manifest.Type == "firmware")
            {
                this.BundleType = BundleType.Firmware;
                this.BinaryContent = await this.ReadFileToArray(this.Manifest.Firmware.Filename, this.Manifest.Firmware.Size);
            }
            else
            {
                this.BundleType = BundleType.Application;
                this.BinaryContent = await this.ReadFileToArray(this.Manifest.ApplicationManifest.Filename, this.Manifest.ApplicationManifest.Size);

                // Convert first part to app manifest
#if NETFX_CORE  && !WINDOWS_PHONE_APP
                byte[] buffer = new byte[Marshal.SizeOf<ApplicationMetadata>()];
#else
                byte[] buffer = new byte[Marshal.SizeOf(typeof(ApplicationMetadata))];
#endif
                Array.Copy(this.BinaryContent, 0, buffer, 0, buffer.Length);
                this.Application = buffer.AsStruct<ApplicationMetadata>();
            }

            this.HasResources = this.Manifest.Resources.Size != 0;
            if (this.HasResources)
            {
                this.Resources = await this.ReadFileToArray(this.Manifest.Resources.Filename, this.Manifest.Resources.Size);
            }
        }