Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Forms/NewProjectForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 50 additions & 10 deletions src/Forms/NewProjectForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ namespace Oxide.Patcher
{
public partial class NewProjectForm : Form
{
private bool _textBoxNameReady = false, _textBoxDirectoryReady = false, _textBoxFileReady = false;

public NewProjectForm()
{
InitializeComponent();
_textBoxNameReady = !string.IsNullOrWhiteSpace(nametextbox.Text);
_textBoxDirectoryReady = !string.IsNullOrWhiteSpace(directorytextbox.Text);
_textBoxFileReady = !string.IsNullOrWhiteSpace(filenametextbox.Text);
ToggleCreateButton();
}

private void NewProjectForm_Load(object sender, EventArgs e)
Expand All @@ -28,12 +34,9 @@ private void selectdirectorybutton_Click(object sender, EventArgs e)
DialogResult result = selectdirectorydialog.ShowDialog(this);
if (result == DialogResult.OK)
{
if (!Directory.EnumerateFiles(selectdirectorydialog.SelectedPath).Any(x => x.EndsWith(".dll") || x.EndsWith(".exe")))
if (CheckTargetDirectory(selectdirectorydialog.SelectedPath))
{
if (MessageBox.Show(this, "The specified directory does not contain any dll files. Continue anyway?", "Oxide Patcher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
{
return;
}
return;
}

//PatcherForm owner = Owner as PatcherForm;
Expand Down Expand Up @@ -69,21 +72,26 @@ private void cancelbutton_Click(object sender, EventArgs e)
private void createbutton_Click(object sender, EventArgs e)
{
// Verify
if (!filenametextbox.Text.EndsWith(".opj"))
{
filenametextbox.Text += ".opj";
}

if (!Directory.Exists(directorytextbox.Text))
{
MessageBox.Show(this, "The target directory is invalid.", "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(this, $"The target directory does not exist!\n{directorytextbox.Text}", "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

if (!Directory.Exists(Path.GetDirectoryName(filenametextbox.Text)))
if (CheckTargetDirectory(directorytextbox.Text))
{
MessageBox.Show(this, "The filename is invalid.", "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

if (nametextbox.TextLength == 0)
string fileDir = Path.GetDirectoryName(filenametextbox.Text);
if (!Directory.Exists(fileDir))
{
MessageBox.Show(this, "The project name is invalid.", "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(this, $"The project directory does not exist!\n{fileDir}", "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

Expand All @@ -100,5 +108,37 @@ private void createbutton_Click(object sender, EventArgs e)
// Close
Close();
}

private void nametextbox_TextChanged(object sender, EventArgs e)
{
_textBoxNameReady = !string.IsNullOrWhiteSpace(nametextbox.Text);
ToggleCreateButton();
}

private void directorytextbox_TextChanged(object sender, EventArgs e)
{
_textBoxDirectoryReady = !string.IsNullOrWhiteSpace(directorytextbox.Text);
ToggleCreateButton();
}

private void filenametextbox_TextChanged(object sender, EventArgs e)
{
_textBoxFileReady = !string.IsNullOrWhiteSpace(filenametextbox.Text);
ToggleCreateButton();
}

// Toggle Create Button
private void ToggleCreateButton() => createbutton.Enabled = _textBoxNameReady && _textBoxDirectoryReady && _textBoxFileReady;

// Checking the target directory for libraries
private bool CheckTargetDirectory(string path)
{
if (!Directory.EnumerateFiles(path).Any(x => x.EndsWith(".dll") || x.EndsWith(".exe")) &&
MessageBox.Show(this, "The specified directory does not contain any dll files. Continue anyway?", "Oxide Patcher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
{
return true;
}
return false;
}
}
}