Example #1
0
        static void p(string[] args)
        {
            //https://github.com/Hexxeh/libpebble/blob/master/pebble/pebble.py
            Dictionary <string, string> argmap = new Dictionary <string, string>();

            argmap["pebble_id"] = null;

            for (int i = 0; i < args.Length; ++i)
            {
                var arg = args[i];
                if (arg == "--test")
                {
                    argmap["test"] = "yes";
                }
                else if (arg == "--pebble_id")
                {
                    var addr = i + 1 < args.Length?args[++i]:null;
                    if (addr.Length > 4)
                    {
                        // assume BT addr or shortcut
                        addr = addr.Replace(":", "");
                        addr = addr.Substring(addr.Length - 4, 4);
                    }
                    argmap["pebble_id"] = addr;
                }
                else if (arg == "--nolaunch")
                {
                    argmap["no_launch"] = "";
                }
                else if (arg == "list")
                {
                    argmap["list"] = "";
                }
                else if (arg == "load")
                {
                    argmap["load"] = i + 1 < args.Length ? args[++i] : null;
                }
                else if (arg == "reinstall")
                {
                    argmap["load"]   = i + 1 < args.Length ? args[++i] : null;
                    argmap["unload"] = argmap["load"];
                }
            }
            if (argmap.ContainsKey("test"))
            {
                TestPack();
                return;
            }
            var pebble = Pebble.GetPebble(argmap["pebble_id"]);

            try
            {
                pebble.Connect();
            }
            catch (System.IO.IOException e)
            {
                Console.Write("Connection failed: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Press enter to exit.");
                Console.ReadLine();
                return;
            }
            Console.WriteLine("Successfully connected!");
            Console.WriteLine(pebble);

            if (argmap.ContainsKey("list"))
            {
                Console.WriteLine(pebble.GetAppbankContents().AppBank);
            }
            else if (argmap.ContainsKey("load"))
            {
                if (argmap.ContainsKey("unload"))
                {
                    PebbleBundle pb   = new PebbleBundle(argmap["load"]);
                    var          apps = pebble.GetAppbankContents().AppBank.Apps;
                    var          app  = apps.Find(a => pb.Application.AppName == a.Name);
                    if (app.Name != null) // in case it didn't find it
                    {
                        pebble.RemoveApp(app);
                    }
                }
                AddApp(pebble, argmap["load"]);
            }
        }