using System;
using System.IO;
using System.Windows.Forms;

namespace QC.QMSCT;

public class FileFolderBrowser
{
	public static string GetFile(string filter, string initialDir)
	{
		string result = "";
		Directory.GetCurrentDirectory();
		OpenFileDialog openFileDialog = new OpenFileDialog();
		openFileDialog.InitialDirectory = initialDir;
		openFileDialog.Filter = filter;
		openFileDialog.FilterIndex = 1;
		openFileDialog.RestoreDirectory = true;
		if (openFileDialog.ShowDialog() == DialogResult.OK)
		{
			result = openFileDialog.FileName;
		}
		return result;
	}

	public static string GetFileToSave(string filter)
	{
		string result = "";
		string currentDirectory = Directory.GetCurrentDirectory();
		SaveFileDialog saveFileDialog = new SaveFileDialog();
		saveFileDialog.InitialDirectory = currentDirectory;
		saveFileDialog.Filter = filter;
		saveFileDialog.FilterIndex = 1;
		saveFileDialog.RestoreDirectory = true;
		if (saveFileDialog.ShowDialog() == DialogResult.OK)
		{
			result = saveFileDialog.FileName;
		}
		return result;
	}

	public static string GetFileToSave(string initialDirectory, string filter)
	{
		string result = "";
		SaveFileDialog saveFileDialog = new SaveFileDialog();
		saveFileDialog.InitialDirectory = initialDirectory;
		saveFileDialog.Filter = filter;
		saveFileDialog.FilterIndex = 1;
		saveFileDialog.RestoreDirectory = true;
		if (saveFileDialog.ShowDialog() == DialogResult.OK)
		{
			result = saveFileDialog.FileName;
		}
		return result;
	}

	public static string GetFolderName(string initialDir)
	{
		string result = "";
		FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
		folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
		folderBrowserDialog.SelectedPath = initialDir;
		folderBrowserDialog.ShowNewFolderButton = true;
		if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
		{
			result = folderBrowserDialog.SelectedPath;
		}
		return result;
	}
}
