Esempio n. 1
0
        public static string EnsureDirectoryExists(string directory)
        {
            directory = MyFile.SafeDirectory(directory);
            if (!Directory.Exists(directory))
            {
                try
                {
                    Directory.CreateDirectory(directory);
                }
                catch (Exception e)
                {
                    if (directory.IndexOf("log") != -1)
                    {
                        MyLog.Add(e.ToString());
                    }
                    else if (Application.OpenForms.Count > 0)
                    {
                        MessageBox.Show("Unable to create the directory [" + directory + "]");
                    }
                    return(null);
                }
            }

            return(directory);
        }
Esempio n. 2
0
        public static string EnsureDataFile(string name, string extension, string subDir, string appendName = null)
        {
            if (String.IsNullOrEmpty(exePath))
            {
                SetAppInfo();
            }

            subDir = MyFile.SafeDirectory(subDir);
            string dataDirectory = exeDirectory + @"\" + subDir;

            if (!Directory.Exists(dataDirectory))
            {
                try
                {
                    Directory.CreateDirectory(dataDirectory);
                }
                catch (Exception e)
                {
                    if (subDir.IndexOf("log") != -1)
                    {
                        MyLog.Add(e.ToString());
                    }
                    else if (Application.OpenForms.Count > 0)
                    {
                        MessageBox.Show("Unable to create the data directory [" + dataDirectory + "]");
                    }
                    return(null);
                }
            }

            if (appendName != null)
            {
                appendName = "_" + appendName;

                appendName = MyFile.SafeFileName(appendName);
            }


            string file = dataDirectory + @"\" + name + appendName + "." + extension;

            return(file);
        }
        private void buttonSaveSource_Click(object sender, EventArgs e)
        {
            string alias     = textBoxAlias.Text.Trim();
            string type      = VideoFileEnums.sourceType.GetTextByValue(comboBoxType.SelectedValue);
            string directory = textBoxDirectory.Text.Trim();

            string message = "";

            if (alias == "")
            {
                message += "Enter an Alias for this Video Source." + Environment.NewLine;
            }
            if (directory.Length < 3)
            {
                message += "Select a Directory for this Video Source" + Environment.NewLine;
            }
            foreach (ListViewItem listViewItemCheck in listViewSource.Items)
            {
                string aliasCheck     = listViewItemCheck.SubItems[0].Text;
                string directoryCheck = listViewItemCheck.SubItems[1].Text;

                if (alias == aliasCheck)
                {
                    message += "Alias [" + alias + "] already exists." + Environment.NewLine;
                    message += "Enter an unique Alias for this Video Source." + Environment.NewLine;
                }
                if (directory == directoryCheck)
                {
                    message += "Directory [" + directory + "] already exists." + Environment.NewLine;
                    message += "Select an unique Directory for this Video Source." + Environment.NewLine;
                }
            }
            if (message != "")
            {
                MessageBox.Show(message);
                return;
            }

            // add to source list
            alias     = MyFile.SafeFileName(alias);
            directory = MyFile.SafeDirectory(directory);
            ListViewItem listViewItem = new ListViewItem(alias);

            listViewItem.SubItems.Add(type);
            listViewItem.SubItems.Add("");
            listViewSource.Items.Add(listViewItem);

            // add to settings
            ConfigSettings.Source source = new ConfigSettings.Source();
            source.alias     = alias;
            source.directory = directory;
            source.type      = type;
            Config.settings.sources.Add(source);

            // clear form
            ClearSourceForm();

            buttonSaveSource.Enabled = false; // no edits

            // select added item and infer scan
            listViewItem = listViewSource.FindItemWithText(source.alias);
            if (listViewItem != null)
            {
                listViewItem.Selected = true;
            }
            buttonScanSource.Focus();

            // video list ui will be update when user rescans
            // video list xml will be updated on main form close
            // settings xml will be updated on main form close, and options form closes
        }