예제 #1
0
        private static void BuildRootDocument(FrmBuildHtmlDocument.ProcessInfo ProcessInfoHandler)
        {
            if (ProcessInfoHandler != null)
            {
                ProcessInfoHandler("RememberIt.html");
            }

            string root_path = Globals.GetCardsPath();

            string[] group_paths = Globals.GetPathOfEachGroup();
            if (group_paths == null)
            {
                return;
            }

            byte[] file_bytes     = RememberItTemplate;
            string card_group_doc = ASCIIEncoding.ASCII.GetString(file_bytes);

            card_group_doc = card_group_doc.Replace("$groups", Globals.GetButtonsForGroups());

            file_bytes = ASCIIEncoding.ASCII.GetBytes(card_group_doc);

            if (file_bytes.Length <= 3)
            {
                return;
            }
            file_bytes[0] = 0xEF;
            file_bytes[1] = 0xBB;
            file_bytes[2] = 0xBF;
            string html_file_name = root_path + "/RememberIt.html";

            File.WriteAllBytes(html_file_name, file_bytes);

            Process.Start(html_file_name);
        }
예제 #2
0
        private bool CheckCardsFolder()
        {
            string cards_path = Globals.GetCardsPath();

            if (Directory.Exists(cards_path) == true)
            {
                return(true);
            }
            else
            {
                try
                {
                    MessageBox.Show("Unable to locate cards folder. Trying to create it.");
                    DirectoryInfo inf = Directory.CreateDirectory(cards_path);
                    if (inf.Exists)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch
                {
                    MessageBox.Show("Unable to create 'cards' folder!");
                    return(false);
                }
            }
        }
예제 #3
0
 public static string[] GetPathOfEachGroup()
 {
     try
     {
         string[] groups = Directory.GetDirectories(Globals.GetCardsPath());
         return(groups);
     }
     catch
     {
         return(null);
     }
 }
예제 #4
0
        void mnuRemoveHtmlDocs_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult res = MessageBox.Show("Remove all HTML documents?", "Warning", MessageBoxButton.YesNoCancel);

            if (res != MessageBoxResult.Yes)
            {
                return;
            }

            int cnt      = 0;
            int fail_cnt = 0;

            string[] all_files = Globals.GetAllFiles(Globals.GetCardsPath());
            for (int i = 0; i < all_files.Length; i++)
            {
                FileInfo fi = new FileInfo(all_files[i]);
                if (fi.Extension.ToLower() == ".html")
                {
                    try
                    {
                        File.Delete(all_files[i]);
                        cnt++;
                    }
                    catch (Exception ex)
                    {
                        fail_cnt++;
                        continue;
                    }
                }
            }

            if (fail_cnt == 0)
            {
                string msg = string.Format("Removed Files: {0}", cnt);
                MessageBox.Show(msg);
            }
            else
            {
                string msg = string.Format("Removed Files: {0}, Unremovable Files: {1}", cnt, fail_cnt);
                MessageBox.Show(msg);
            }
        }
        private void btnNewGroup_Click(object sender, EventArgs e)
        {
            if (txtNewGroupName.Text.Trim() == "")
            {
                MessageBox.Show("Invalid Group Name.");
                return;
            }

            string cards_path = Globals.GetCardsPath();
            string grp_path   = cards_path + txtNewGroupName.Text.Trim();

            try
            {
                DirectoryInfo di = Directory.CreateDirectory(grp_path);
                if (di.Exists)
                {
                    MessageBox.Show("Group Created!");
                    this.Init();
                    string grp_name = Globals.GetLastPartOfDir(di.FullName);
                    for (int i = 0; i < cmbGroups.Items.Count; i++)
                    {
                        if (cmbGroups.Items[i].ToString() == grp_name)
                        {
                            cmbGroups.SelectedIndex = i;
                            break;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Unable to create group");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid Group Name.\r\n" + ex.Message);
            }
        }
예제 #6
0
        void mnuOpenCardsRoot_Click(object sender, RoutedEventArgs e)
        {
            string cp = Globals.GetCardsPath();

            Process.Start(cp);
        }
예제 #7
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();
        }