Esempio n. 1
0
        /// <summary>
        /// Create a new PebbleBundle from a .pwb file and parse its metadata.
        /// </summary>
        /// <param name="path">The relative or full path to the file.</param>
        public P3bbleBundle(String path)
        {
            Stream jsonstream;
            Stream binstream;

            _privateName = path;

            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();

            if (!file.FileExists(path))
            {
                throw new FileNotFoundException("the file could not be found in the isolated storage");
            }

            FullPath = Path.GetFullPath(path);
            Bundle   = new UnZipper(file.OpenFile(path, FileMode.Open));

            if (Bundle.FileNamesInZip.Contains("manifest.json"))
            {
                jsonstream = Bundle.GetFileStream("manifest.json");
            }
            else
            {
                throw new ArgumentException("manifest.json not found in archive - not a Pebble bundle.");
            }

            var serializer = new DataContractJsonSerializer(typeof(P3bbleBundleManifest));


            Manifest = serializer.ReadObject(jsonstream) as P3bbleBundleManifest;
            jsonstream.Close();

            HasResources = (Manifest.Resources.Size != 0);

            if (Manifest.Type == "firmware")
            {
                BundleType = BundleTypes.Firmware;
            }
            else
            {
                BundleType = BundleTypes.Application;
                if (Bundle.FileNamesInZip.Contains(Manifest.Application.Filename))
                {
                    binstream = Bundle.GetFileStream(Manifest.Application.Filename);
                }
                else
                {
                    String format = "App file {0} not found in archive";
                    throw new ArgumentException(String.Format(format, Manifest.Application.Filename));
                }

                Application = Util.ReadStruct <P3bbleApplicationMetadata>(binstream);
                binstream.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new PebbleBundle from a .pwb file and parse its metadata.
        /// </summary>
        /// <param name="path">The relative or full path to the file.</param>
        public P3bbleBundle(String path)
        {
            Stream jsonstream;
            Stream binstream;
            _privateName = path;

            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
            if (!file.FileExists(path))
                throw new FileNotFoundException("the file could not be found in the isolated storage");

            FullPath = Path.GetFullPath(path);
            Bundle = new UnZipper(file.OpenFile(path, FileMode.Open));

            if (Bundle.FileNamesInZip.Contains("manifest.json"))
            {
                jsonstream = Bundle.GetFileStream("manifest.json");
            }
            else
            {
                throw new ArgumentException("manifest.json not found in archive - not a Pebble bundle.");
            }

            var serializer = new DataContractJsonSerializer(typeof(P3bbleBundleManifest));

            Manifest = serializer.ReadObject(jsonstream) as P3bbleBundleManifest;
            jsonstream.Close();

            HasResources = (Manifest.Resources.Size != 0);

            if (Manifest.Type == "firmware")
            {
                BundleType = BundleTypes.Firmware;
            }
            else
            {
                BundleType = BundleTypes.Application;
                if (Bundle.FileNamesInZip.Contains(Manifest.Application.Filename))
                {
                    binstream = Bundle.GetFileStream(Manifest.Application.Filename);
                }
                else
                {
                    String format = "App file {0} not found in archive";
                    throw new ArgumentException(String.Format(format, Manifest.Application.Filename));
                }

                Application = Util.ReadStruct<P3bbleApplicationMetadata>(binstream);
                binstream.Close();
            }
        }