Exemplo n.º 1
0
        // ----- ----- //

        #endregion

        #endregion

        #region Dialogs

        void TextMessageDialog(string Title, string Content, bool DarkMode = false)
        {

            /*

            MessagedialogWindow dialog = null;
            bool DarkListnerNeeded = true;

            if (webcamimagePage.Visibility == Visibility.Visible)
            {
                dialog = new MessagedialogWindow(Title, Message, true);
                DarkListnerNeeded = false;
            }

            if (DarkListnerNeeded)
            {
                if (DarkMode == true)
                    dialog = new MessagedialogWindow(Title, Message, true);
                else
                    dialog = new MessagedialogWindow(Title, Message);
            }

            dialog.Owner = this;
            dialog.ShowDialog();

            */


            var dialog = new Popups.MessageDialog();

            dialog.Title = Title;
            dialog.Content = Content;

            dialog.ShowDialog();
        }
Exemplo n.º 2
0
        private void infoButton_Click(object sender, RoutedEventArgs e)
        {
            if (READONLY_MODE | DISABLE_ARCHIVEORG | DISABLE_LOCALSAVE | DISABLE_WEBCAMEDITOR)
                TextMessageDialog("Certain functions have been disabled.", "You've probably used one or more of the command line switches that disable certain things in the program.\n" +
                    "READONLY: " + READONLY_MODE + "\n" +
                    "DISABLE_ARCHIVEORG: " + DISABLE_ARCHIVEORG + "\n" +
                    "DISABLE_LOCALSAVE: " + DISABLE_LOCALSAVE + "\n" +
                    "DISABLE_WEBCAMEDITOR: " + DISABLE_WEBCAMEDITOR);

            if (HEARTBEAT_CONFIGCHANGED)
            {
                Popups.MessageDialog dlg = new Popups.MessageDialog();
                dlg.Title = "An update was made to the default configuration";
                dlg.Content = "You're using the default configuration, meaning you haven't changed the default settings of Webcam Viewer.\nWould you like to update to the latest configuration?";

                dlg.FirstButtonContent = "Sure, update!";
                dlg.SecondButtonContent = "No, thanks";
                dlg.ThirdButtonContent = "Don't show this again";

                int dlg_result = dlg.ShowDialogWithResult();

                if (dlg_result == 0)
                {
                    SwitchToPage(3);

                    DispatcherTimer faketimer = new DispatcherTimer();
                    faketimer.Interval = new TimeSpan(0, 0, 8);
                    faketimer.Tick += (s, ev) => { SwitchToPage(0); TextMessageDialog("Update failed", "Could not update the local configuration."); faketimer.Stop(); };
                    faketimer.Start();
                }
                else if (dlg_result == 2)
                {
                    Properties.Settings.Default.defaultconfig_heartbeat = false;
                    Properties.Settings.Default.Save();
                }
            }
        }
Exemplo n.º 3
0
        // ----- Context menu ----- //

        private void titlebarGrid_contextmenu_ResetWindowSize_Click(object sender, RoutedEventArgs e)
        {
#if DEBUG
            // Result dialog debug
            Popups.MessageDialog dlg = new Popups.MessageDialog();
            dlg.Title = "Are you sure you want to reset the window size?";
            dlg.Content = "The window size will be reset to 800x675.\nContinue?";
            dlg.FirstButtonContent = "Continue";
            dlg.SecondButtonContent = "Cancel";

            if (dlg.ShowDialogWithResult() == 1)
                return;
#endif

            this.Width = 800;
            this.Height = 600 + 30 + 45;
            CenterWindowOnScreen();
        }
Exemplo n.º 4
0
        public void ReadConfigurationFile(string configfile_path, bool applyConfig)
        {
            Stream stream = null;
            Popups.MessageDialog progressdialog = new Popups.MessageDialog();

            if (!(configfile_path.Contains("http") || configfile_path.Contains("ftp")))
            {
                try
                {
                    stream = File.OpenRead(configfile_path);
                }
                catch (Exception ex)
                {
                    TextMessageDialog("Cannot read the configuration file", "Error: " + ex.Message);
                }
            }
            else
            {
                WebClient client = new WebClient();

                Uri configfile_path_Uri = new Uri(configfile_path);

                try
                {
                    stream = client.OpenRead(configfile_path_Uri);
                }
                catch (Exception ex)
                {
                    TextMessageDialog("Could not grab the configuration file", "Make sure you have a working internet connection, or that the file exists at the URL you provided, and try again.\nError: " + ex.Message);
                    return;
                }
            }

            StreamReader reader = new StreamReader(stream);

            string configfile_Content = reader.ReadToEnd();

            string[] configfile_Content_linesArray = configfile_Content.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

            progressdialog.Close();

            if (showDebugDialogs)
                TextMessageDialog("", configfile_Content, true);

            bool shouldContinue = false;

            int lineNumber = 0;
            int continueFrom_LineNumber = 0;

            foreach (string line in configfile_Content_linesArray)
            {
                if (shouldContinue)
                {
                    if (lineNumber != continueFrom_LineNumber)
                    {
                        // linenumber++ at the end
                    }
                    else
                        shouldContinue = false;
                }
                else
                {
                    if (line.StartsWith("\"")) // it's a property name, begings with "
                    {
                        PropertyNames.Add(line.Substring(1, line.Length - 2));
                    }
                }

                List<string> valuesToAdd = new List<string>();

                if (line.StartsWith("{")) // it's first identifier of a value, begins with {
                {
                    int actuallinecounter = 0;
                    int linecounter = lineNumber;
                    int startPoint = 0;
                    //int endPoint = 0;
                    int IndexToAddTo = 0;

                    int number = 1;

                    if (configfile_Content_linesArray[linecounter + 1].StartsWith("}"))
                        number -= 1;

                    foreach (string line2 in configfile_Content_linesArray)
                    {
                        if (actuallinecounter == linecounter)
                        {
                            if (configfile_Content_linesArray[linecounter + number].StartsWith("  ")) // two spaces
                            {
                                startPoint = linecounter + 1;

                                valuesToAdd.Add(configfile_Content_linesArray[startPoint].Remove(0, 2));
                            }
                            else if ((configfile_Content_linesArray[linecounter + 1]).StartsWith("}"))
                            {
                                //endPoint = linecounter;
                                actuallinecounter++;

                                break;
                            }

                            linecounter++;
                            actuallinecounter++;
                        }
                        else
                        {
                            actuallinecounter++;
                        }
                    }

                    IndexToAddTo++;

                    string[] _finalvaluesToAdd = new string[valuesToAdd.Count];
                    valuesToAdd.CopyTo(_finalvaluesToAdd);

                    PropertyValues.Add(_finalvaluesToAdd);

                    continueFrom_LineNumber = actuallinecounter;
                    shouldContinue = true;
                }

                lineNumber++;

            }

            if (showDebugDialogs)
            {
                string propertyvalues_string = "";

                foreach (string[] array in PropertyValues)
                {
                    propertyvalues_string += String.Join("\n", array);
                    propertyvalues_string += "\n";
                }

                TextMessageDialog("", String.Join("\n", PropertyNames.ToArray()) + "\n\n----------\n\n" + String.Join("\n", propertyvalues_string));
            }

            if (applyConfig)
                ApplyConfigFileSettings();
        }
Exemplo n.º 5
0
        void TextMessageDialog(string Title, string Content, bool DarkMode = false)
        {
            var dialog = new Popups.MessageDialog();

            dialog.Title = Title;
            dialog.Content = Content;

            dialog.ShowDialog();
        }
Exemplo n.º 6
0
        void ApplyConfigFileSettings()
        {
            Popups.MessageDialog confirmDialog = new Popups.MessageDialog();

            confirmDialog.Title = "Are you sure you want to apply this configuration file?";
            confirmDialog.Content = "Make sure you backup your current configuration, there's no way to get your current configuration back once you continue.";

            confirmDialog.FirstButtonContent = "Continue";
            confirmDialog.SecondButtonContent = "Cancel";

            if (confirmDialog.ShowDialogWithResult() == 0)
            {
                bool invalid_cameracustomizations = false;

                if (PropertyNames.Contains("camera_names") || PropertyNames.Contains("camera_urls"))
                {
                    if (PropertyNames.Contains("camera_names") & !PropertyNames.Contains("camera_urls") || !PropertyNames.Contains("camera_names") & PropertyNames.Contains("camera_urls"))
                    {
                        Popups.MessageDialog dlg = new Popups.MessageDialog();
                        dlg.Title = "The camera customizations are invalid";
                        dlg.Content = "Check the configuration file and try again.\nShould we apply the rest of the settings? (if there are any)";

                        dlg.FirstButtonContent = "Yes, apply them.";
                        dlg.SecondButtonContent = "Cancel";

                        if (dlg.ShowDialogWithResult() == 1)
                            return;
                        else
                            invalid_cameracustomizations = true;
                    }
                }

                if (PropertyNames.Contains("camera_names") & PropertyNames.Contains("camera_urls"))
                {
                    string[] stringSeparators = new string[] { "\n" };

                    string[] s_names = PropertyValues[PropertyNames.IndexOf("camera_names")];

                    string[] s_urls = PropertyValues[PropertyNames.IndexOf("camera_urls")];

                    if (s_names.Length != s_urls.Length)
                    {
                        Popups.MessageDialog dlg = new Popups.MessageDialog();
                        dlg.Title = "The camera customizations are invalid";
                        dlg.Content = "There are more or less camera entries in one of the sections. Check the configuration file and try again.\nShould we apply the rest of the settings? (if there are any)";

                        dlg.FirstButtonContent = "Yes, apply them.";
                        dlg.SecondButtonContent = "Cancel";

                        if (dlg.ShowDialogWithResult() == 1)
                            return;
                        else
                            invalid_cameracustomizations = true;
                    }
                }

                int counter = 0;

                foreach (string name in PropertyNames)
                {

                    string[] Value = PropertyValues[counter];

                    if (name == "camera_names" || name == "camera_urls")
                    {
                        if (invalid_cameracustomizations)
                        {
                            counter++;
                            break;
                        }
                        else
                        {
                            System.Collections.Specialized.StringCollection camera_namesCollection = Settings[name] as System.Collections.Specialized.StringCollection;
                            camera_namesCollection.Clear();
                            camera_namesCollection.AddRange(Value);
                        }

                        counter++;
                    }
                    else
                    {
                        bool bool_tryParse_result;
                        int int_tryParse_result;

                        //if (Value[0] == "true" || Value[0] == "false")
                            if (bool.TryParse(Value[0], out bool_tryParse_result) == true)
                                Settings[name] = bool.Parse(Value[0]);
                            else if (int.TryParse(Value[0], out int_tryParse_result) == true)
                                Settings[name] = int.Parse(Value[0]);

                        counter++;
                    }
                }

                Settings.Save();
            }
            else
                return;
        }