Пример #1
0
        public MainWindow()
        {
            InitializeComponent();

            JsonParser J_S        = new JsonParser();
            FirsrHirc  jsonObject = J_S.Parse();

            installer_.Title += jsonObject.install.version;


            //new log collection
            logItems = new ObservableCollection <Item>()
            {
                new Item()
                {
                    Text = "Logger"
                }
            };


            var bc = new BrushConverter();

            Utilities.LogTextColor = (System.Windows.Media.Brush)bc.ConvertFromString(Constants.White);
            Utilities.Hexagon      = "";
            Utilities.EnableDebug  = false;

            //bind the log collection to its UI asset
            log.ItemsSource = logItems;


            //set the infinity icon
            string iconsPath;

            iconsPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "INFINITY_logo.png");
            if (File.Exists(iconsPath))
            {
                logo.Source = new BitmapImage(new Uri(iconsPath, UriKind.RelativeOrAbsolute));
            }


            //Start the backgroung workers
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += worker_DoWork;
            worker.RunWorkerAsync();

            BackgroundWorker worker_check_connection = new BackgroundWorker();

            worker_check_connection.DoWork += worker_CheckConnection;
            worker_check_connection.RunWorkerAsync();

            BackgroundWorker worker_check_battery = new BackgroundWorker();

            worker_check_battery.DoWork += worker_CheckBattary;
            worker_check_battery.RunWorkerAsync();


            //read the serial number
            var t = Task.Run(() =>
            {
                try
                {
                    util.Check_devices();
                    Thread.Sleep(1000);
                    l_serial_val.Content = Utilities.SerialNum;
                }
                catch (Exception ex)
                {
                    //util.change_color = true;
                    Console.WriteLine(ex);
                }
            });
        }
Пример #2
0
        private void b_install_Click(object sender, RoutedEventArgs e)
        {
            string[] empty   = {};
            string[] dir     = { };
            string[] results = { };
            var      dialog  = new CommonOpenFileDialog();

            dialog.IsFolderPicker = true;

            //CommonFileDialogResult result = dialog.ShowDialog();
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                dir = dialog.FileNames.ToArray();
            }
            Install install = new Install();

            if (dir.Length < 1)
            {
                return;
            }


            string[] files = Directory.GetFiles(dir[0], "*.img",
                                                SearchOption.AllDirectories);

            List <string> files_ = new List <string>();
            List <string> inGame = new List <string>();

            JsonParser J_S        = new JsonParser();
            FirsrHirc  jsonObject = J_S.Parse();
            var        t          = jsonObject.install.list;

            foreach (var im in t)
            {
                inGame.Add(im.image);
            }

            foreach (var file in files)
            {
                string g = System.IO.Path.GetFileName(file);
                if (inGame.Contains(g))
                {
                    files_.Add(file);
                }
            }


            //show all images in the folder

            var items = new installedItems(files_.ToList());

            if (!(bool)items.ShowDialog() == true)
            {
                return;
            }

            l_calib_files_val.Content  = "None";
            l_config_files_val.Content = "None";
            l_engine_val.Content       = "None";
            l_hexagon_val.Content      = "None";
            l_release_val.Content      = "None";
            l_config_files_val.Content = "None";
            Utilities.Hexagon          = "";

            Item k = new Item()
            {
                Text = "Start instllation, it may take few minutes."
            };

            logItems.Add(k);
            var backgroundScheduler = TaskScheduler.Default;
            var uiScheduler         = TaskScheduler.FromCurrentSynchronizationContext();
            var uiContext           = SynchronizationContext.Current;

            this.Dispatcher.Invoke((Action) delegate
            {
                Item i = new Item()
                {
                    Text = "wait while device is rebooting, the installation wait 60 sec after reboot"
                };
                Task.Factory.StartNew(delegate { install.Enter_Boot_Loader(empty); },
                                      backgroundScheduler).
                ContinueWith(delegate { uiContext.Send(x => logItems.Add(Utilities.TextToLog), null); }, uiScheduler).
                ContinueWith(delegate { uiContext.Send(x => logItems.Add(i), null); }, uiScheduler).
                ContinueWith(delegate { install.Fastboot_Reboot(); }, backgroundScheduler).
                ContinueWith(delegate { uiContext.Send(x => logItems.Add(i), null); }, uiScheduler);
            });
        }