Example #1
0
        static async Task DeleteApp(Pebble pebble)
        {
            var applist = (await pebble.GetAppbankContentsAsync()).AppBank.Apps;

            Console.WriteLine("Choose an app to remove");
            AppBank.App result = SharpMenu <AppBank.App> .WriteAndPrompt(applist);

            AppbankInstallResponse ev = await pebble.RemoveAppAsync(result);

            Console.WriteLine(ev.MsgType);
        }
Example #2
0
        public async Task InstallAppAsync(AppBundle bundle, IProgress <ProgressValue> progress = null)
        {
            if (bundle == null)
            {
                throw new ArgumentNullException("bundle");
            }

            if (progress != null)
            {
                progress.Report(new ProgressValue("Removing previous install(s) of the app if they exist", 1));
            }
            ApplicationMetadata metaData = bundle.AppMetadata;
            UUID uuid = metaData.UUID;

            AppbankInstallResponse appbankInstallResponse = await RemoveAppByUUID(uuid);

            if (appbankInstallResponse.Success == false)
            {
                return;
            }

            if (progress != null)
            {
                progress.Report(new ProgressValue("Getting current apps", 20));
            }
            AppbankResponse appBankResult = await GetAppbankContentsAsync();

            if (appBankResult.Success == false)
            {
                throw new PebbleException("Could not obtain app list; try again");
            }
            AppBank appBank = appBankResult.AppBank;

            byte firstFreeIndex = 1;

            foreach (App app in appBank.Apps)
            {
                if (app.Index == firstFreeIndex)
                {
                    firstFreeIndex++;
                }
            }
            if (firstFreeIndex == appBank.Size)
            {
                throw new PebbleException("All app banks are full");
            }

            if (progress != null)
            {
                progress.Report(new ProgressValue("Transferring app to Pebble", 40));
            }

            if (await PutBytes(bundle.App, firstFreeIndex, TransferType.Binary) == false)
            {
                throw new PebbleException("Failed to send application binary pebble-app.bin");
            }

            if (bundle.HasResources)
            {
                if (progress != null)
                {
                    progress.Report(new ProgressValue("Transferring app resources to Pebble", 60));
                }
                if (await PutBytes(bundle.Resources, firstFreeIndex, TransferType.Resources) == false)
                {
                    throw new PebbleException("Failed to send application resources app_resources.pbpack");
                }
            }

            if (progress != null)
            {
                progress.Report(new ProgressValue("Adding app", 80));
            }
            await AddApp(firstFreeIndex);

            if (progress != null)
            {
                progress.Report(new ProgressValue("Done", 100));
            }
        }
Example #3
0
        public async Task InstallAppAsync(PebbleBundle bundle, IProgress <ProgressValue> progress = null)
        {
            if (bundle == null)
            {
                throw new ArgumentNullException("bundle");
            }
            if (bundle.BundleType != PebbleBundle.BundleTypes.Application)
            {
                throw new ArgumentException("Bundle must be an application");
            }

            if (progress != null)
            {
                progress.Report(new ProgressValue("Removing previous install(s) of the app if they exist", 1));
            }
            var metaData = bundle.AppMetadata;
            var uuid     = metaData.UUID;

            AppbankInstallResponse appbankInstallResponse = await RemoveAppByUUID(uuid);

            if (appbankInstallResponse.Success == false)
            {
                return;
            }

            if (progress != null)
            {
                progress.Report(new ProgressValue("Getting current apps", 10));
            }
            AppbankResponse appBankResult = await GetAppbankContentsAsync();

            if (appBankResult.Success == false)
            {
                throw new PebbleException("Could not obtain app list; try again");
            }
            var appBank = appBankResult.AppBank;

            byte firstFreeIndex = 1;

            foreach (var app in appBank.Apps)
            {
                if (app.Index == firstFreeIndex)
                {
                    firstFreeIndex++;
                }
            }
            if (firstFreeIndex == appBank.Size)
            {
                throw new PebbleException("All app banks are full");
            }

            if (progress != null)
            {
                progress.Report(new ProgressValue("Reading app data", 30));
            }

            var zipFile  = ZipFile.Read(bundle.FullPath);
            var appEntry = zipFile.Entries.FirstOrDefault(x => x.FileName == bundle.Manifest.Application.Filename);

            if (appEntry == null)
            {
                throw new PebbleException("Could find application file");
            }

            byte[] appBinary = Util.GetBytes(appEntry);

            if (progress != null)
            {
                progress.Report(new ProgressValue("Transferring app to Pebble", 50));
            }

            if (await PutBytes(appBinary, firstFreeIndex, TransferType.Binary) == false)
            {
                throw new PebbleException(string.Format("Failed to send application binary {0}/pebble-app.bin", bundle.FullPath));
            }

            if (bundle.HasResources)
            {
                var resourcesEntry = zipFile.Entries.FirstOrDefault(x => x.FileName == bundle.Manifest.Resources.Filename);
                if (resourcesEntry == null)
                {
                    throw new PebbleException("Could not find resource file");
                }

                byte[] resourcesBinary = Util.GetBytes(resourcesEntry);
                if (progress != null)
                {
                    progress.Report(new ProgressValue("Transferring app resources to Pebble", 70));
                }
                if (await PutBytes(resourcesBinary, firstFreeIndex, TransferType.Resources) == false)
                {
                    throw new PebbleException(string.Format("Failed to send application resources {0}/app_resources.pbpack", bundle.FullPath));
                }
            }
            if (progress != null)
            {
                progress.Report(new ProgressValue("Adding app", 90));
            }
            await AddApp(firstFreeIndex);

            if (progress != null)
            {
                progress.Report(new ProgressValue("Done", 100));
            }
        }