Exemplo n.º 1
0
 public void Device_List_Refresh_Timer_Tick(object sender, EventArgs e)
 {
     if (!settings.Visible)
     {
         if (File.Exists(@"config.txt"))
         {
             try
             {
                 StreamReader reader = new StreamReader(@"config.txt");
                 for (int i = 0; i < Device_Count; i++)
                 {
                     device_list[i]          = new SessionOptions();
                     device_list[i].HostName = "";
                     device_list[i].UserName = "";
                     device_list[i].Password = "";
                 }
                 PiCam_List.Items.Clear();
                 int count = 0;
                 while (true)
                 {
                     if (string.Equals(reader.ReadLine(), "----"))
                     {
                         PiCam_List.Items.Add(reader.ReadLine());
                         device_list[count].HostName = reader.ReadLine();
                         device_list[count].UserName = reader.ReadLine();
                         device_list[count].Password = reader.ReadLine();
                         device_list[count].Protocol = Protocol.Sftp;
                         device_list[count].GiveUpSecurityAndAcceptAnySshHostKey = true;
                         count++;
                     }
                     else
                     {
                         break;
                     }
                 }
                 reader.Close();
             }
             catch (Exception wrong)
             {
                 Device_List_Refresh_Timer.Enabled = false;
                 MessageBox.Show(wrong.Message, "Error Message", MessageBoxButtons.OK);
             }
         }
         else
         {
             Device_List_Refresh_Timer.Enabled = false;
             if (MessageBox.Show("Possible setting file missing or broken! Do you want to locate it now?", "Setting File Missing", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 if (Config_File_Dialog.ShowDialog() == DialogResult.OK)
                 {
                     File.Copy(Config_File_Dialog.FileName, @"config.txt", true);
                     try
                     {
                         StreamReader reader = new StreamReader(@"config.txt");
                         for (int i = 0; i < Device_Count; i++)
                         {
                             device_list[i]          = new SessionOptions();
                             device_list[i].HostName = "";
                             device_list[i].UserName = "";
                             device_list[i].Password = "";
                         }
                         PiCam_List.Items.Clear();
                         int count = 0;
                         while (true)
                         {
                             if (string.Equals(reader.ReadLine(), "----"))
                             {
                                 PiCam_List.Items.Add(reader.ReadLine());
                                 device_list[count].HostName = reader.ReadLine();
                                 device_list[count].UserName = reader.ReadLine();
                                 device_list[count].Password = reader.ReadLine();
                                 device_list[count].Protocol = Protocol.Sftp;
                                 device_list[count].GiveUpSecurityAndAcceptAnySshHostKey = true;
                                 count++;
                             }
                             else
                             {
                                 break;
                             }
                         }
                         reader.Close();
                     }
                     catch (Exception wrong)
                     {
                         MessageBox.Show(wrong.Message, "Error Message", MessageBoxButtons.OK);
                     }
                 }
             }
         }
         if (PiCam_List.SelectedIndex == -1 && !(PiCam_List.Items.Count == 0))
         {
             PiCam_List.SelectedIndex = 0;
         }
         Device_List_Refresh_Timer.Enabled = false;
     }
 }
Exemplo n.º 2
0
 private void Check_Visibility_Timer_Tick(object sender, EventArgs e)
 {
     if (this.Visible && !last_visible)
     {
         last_visible = true;
         if (File.Exists(@"config.txt"))
         {
             try
             {
                 StreamReader reader = new StreamReader(@"config.txt");
                 i = 0;
                 Device_Select.Items.Clear();
                 while (true)
                 {
                     if (string.Equals(reader.ReadLine(), "----"))
                     {
                         device_list[i, 0] = reader.ReadLine();
                         Device_Select.Items.Add(device_list[i, 0]);
                         device_list[i, 1] = reader.ReadLine();
                         device_list[i, 2] = reader.ReadLine();
                         device_list[i, 3] = reader.ReadLine();
                         i++;
                     }
                     else
                     {
                         break;
                     }
                 }
                 reader.Close();
             }
             catch (Exception haha)
             {
                 MessageBox.Show(haha.Message, "Error Message", MessageBoxButtons.OK);
             }
         }
         else
         {
             if (MessageBox.Show("Possible setting file missing or broken! Do you want to locate it now?", "Setting File Missing", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 if (Config_File_Dialog.ShowDialog() == DialogResult.OK)
                 {
                     File.Copy(Config_File_Dialog.FileName, @"config.txt", true);
                     try
                     {
                         StreamReader reader = new StreamReader(@"config.txt");
                         i = 0;
                         Device_Select.Items.Clear();
                         while (true)
                         {
                             if (string.Equals(reader.ReadLine(), "----"))
                             {
                                 device_list[i, 0] = reader.ReadLine();
                                 Device_Select.Items.Add(device_list[i, 0]);
                                 device_list[i, 1] = reader.ReadLine();
                                 device_list[i, 2] = reader.ReadLine();
                                 device_list[i, 3] = reader.ReadLine();
                                 i++;
                             }
                             else
                             {
                                 break;
                             }
                         }
                         reader.Close();
                     }
                     catch (Exception haha)
                     {
                         MessageBox.Show(haha.Message, "Error Message", MessageBoxButtons.OK);
                     }
                 }
             }
         }
         if (Device_Select.SelectedIndex == -1 && !(Device_Select.Items.Count == 0))
         {
             Device_Select.SelectedIndex = 0;
         }
     }
 }