Example #1
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            dgvCards.Rows.Clear();
            string[] Phone_cards = com.GetListOfCards(cmbPhoneCardGroup.SelectedItem.ToString());
            string[] Pc_cards =null;
            int row = 0;

            foreach (string phone_side_card in Phone_cards)
            {
                int indx = dgvCards.Rows.Add(1);
                dgvCards.Rows[indx].Cells[clmnRow.Index].Value = ++row;
                dgvCards.Rows[indx].Cells[clmnSelectPcCard.Index].Value = false;
                dgvCards.Rows[indx].Cells[clmnCard.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnAction.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnSelectPhCard.Index].Value = false;
                dgvCards.Rows[indx].Cells[clmnCardPhone.Index].Value = Globals.GetLastPartOfDir(phone_side_card);
                dgvCards.Rows[indx].Cells[clmnCardPathPc.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnCardPathPhone.Index].Value = phone_side_card;
                dgvCards.Rows[indx].Cells[clmnCroup.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnManifestDataPc.Index].Value = "";
                dgvCards.Rows[indx].Cells[clmnManifestDataPhone.Index].Value = "";

            }


            if (cmbPcCardGroup.SelectedIndex == 0)
            {
                List<string> all_cards = new List<string>();
                string[] groups = Globals.GetPathOfEachGroup();
                foreach (string group in groups)
                {
                    string[] cards = Globals.GetPathOfEachCard(group);
                    foreach (string card in cards)
                    {
                        all_cards.Add(card);
                    }
                }
                Pc_cards = all_cards.ToArray();
            }
            else
            {
                string group = group = Globals.GetCardsPath() + "\\" + cmbPcCardGroup.SelectedItem.ToString();
                Pc_cards = Globals.GetPathOfEachCard(group);
            }

            if (Phone_cards != null)
            {

                if (Pc_cards!=null) foreach (string card_dir_path in Pc_cards)
                {
                    string card_name = Globals.GetLastPartOfDir(card_dir_path);
                    int idx = Lookup(card_name, dgvCards);
                    if (idx == -1)
                    {
                        int indx = dgvCards.Rows.Add(1);
                        dgvCards.Rows[indx].Cells[clmnRow.Index].Value = ++row;
                        dgvCards.Rows[indx].Cells[clmnSelectPcCard.Index].Value = false;
                        dgvCards.Rows[indx].Cells[clmnCard.Index].Value = card_name;
                        dgvCards.Rows[indx].Cells[clmnAction.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnSelectPhCard.Index].Value = false;
                        dgvCards.Rows[indx].Cells[clmnCardPhone.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnCardPathPc.Index].Value = card_dir_path;
                        dgvCards.Rows[indx].Cells[clmnCardPathPhone.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnCroup.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnManifestDataPc.Index].Value = "";
                        dgvCards.Rows[indx].Cells[clmnManifestDataPhone.Index].Value = "";

                    }
                    else
                    {
                        dgvCards.Rows[idx].Cells[clmnCard.Index].Value = card_name;
                        dgvCards.Rows[idx].Cells[clmnCardPathPc.Index].Value = card_dir_path;
                    }
                }
            }


            // Extract manifest data
            for (int i = 0; i < dgvCards.Rows.Count; i++)
            {
                
                // Extract manifest data of phone-side cards
                string card_path_phone = (string)dgvCards.Rows[i].Cells[clmnCardPathPhone.Index].Value;
                string manifest_phone = "";
                if (card_path_phone != "")
                {
                    manifest_phone = com.GetManifestData(card_path_phone);
                    dgvCards.Rows[i].Cells[clmnManifestDataPhone.Index].Value = manifest_phone;
                }
                

                // Extract manifest data of pc-side cards
                string card_path_pc = (string)dgvCards.Rows[i].Cells[clmnCardPathPc.Index].Value;
                string manifest_pc = "";
                if (card_path_pc != "")
                {
                    manifest_pc = File.ReadAllText(card_path_pc+"/manifest.man");
                    KeyValPair kvp = new KeyValPair('\n','=');
                    kvp.Fill(manifest_pc);
                    manifest_pc = kvp.GetString(';',':');
                    dgvCards.Rows[i].Cells[clmnManifestDataPc.Index].Value = manifest_pc;
                }
            }


            // Define proper action for transfering cards to/from pc from/to phone.
            for (int i = 0; i < dgvCards.Rows.Count; i++)
            {
                string manifest_phone = (string)dgvCards.Rows[i].Cells[clmnManifestDataPhone.Index].Value;
                string manifest_pc = (string)dgvCards.Rows[i].Cells[clmnManifestDataPc.Index].Value;

                if (manifest_phone == "" && manifest_pc == "") continue;
                else if (manifest_phone == "") dgvCards.Rows[i].Cells[clmnAction.Index].Value = "--->";
                else if (manifest_pc == "") dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<---";
                else
                {
                    KeyValPair kvp_phone = new KeyValPair(';', ':');
                    kvp_phone.Fill(manifest_phone);

                    KeyValPair kvp_pc = new KeyValPair(';', ':');
                    kvp_pc.Fill(manifest_pc);


                    double ph_last_modified = 0; 
                    double pc_last_modified = 0;
                    try
                    {
                       ph_last_modified = Double.Parse(kvp_phone.GetVal("last_modified"));
                       pc_last_modified = Double.Parse(kvp_pc.GetVal("last_modified"));
                    }
                    catch
                    {
                        dgvCards.Rows[i].Cells[clmnAction.Index].Value = "!";
                        continue;
                    }

                    if (pc_last_modified == ph_last_modified) dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<--->";
                    else if (pc_last_modified > ph_last_modified) dgvCards.Rows[i].Cells[clmnAction.Index].Value = "--->";
                    else dgvCards.Rows[i].Cells[clmnAction.Index].Value = "<---";
                }

            }

            if (chbxShowDiffs.Checked) ShowOnlyDiffs();
        }