Skip to content

Commit

Permalink
Implemented whitelist override for user's request
Browse files Browse the repository at this point in the history
Whitelist overrides will disable the ability to alter addons.
But this fixes the errors pointed out by users that the program refuses to
load addons not conforming the whitelist.

Also reverts the changes of previous commit 3dae810.

Contains a HEAVY hackfix!
  • Loading branch information
whisperity committed Oct 3, 2014
1 parent 3dae810 commit 46a3d3d
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 53 deletions.
71 changes: 51 additions & 20 deletions SharpGMad/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private Main()
{
InitializeComponent();
UnloadAddon();
tsbCreateAddon.Enabled = !Program.WhitelistOverridden;
}

public Main(string[] args)
Expand Down Expand Up @@ -95,8 +96,30 @@ private void LoadAddon(string path)
}
catch (WhitelistException e)
{
MessageBox.Show(e.Message, "Addon is corrupted", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
if (!Program.WhitelistOverridden)
{
DialogResult ovrride = MessageBox.Show("This addon is against the GMA whitelist rules defined by garry!\n" +
e.Message + "\n\nFor datamining purposes, it is still possible to open this addon, HOWEVER " +
"opening this addon is an illegal operation and SharpGMad will prevent further modifications.\n\n" +
"Do you want to enable forced opening of addons by overriding the whitelist?",
"Addon is corrupted", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (ovrride == DialogResult.No)
{
MessageBox.Show(e.Message, "Addon is corrupted", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
else if (ovrride == DialogResult.Yes)
{
Program.WhitelistOverridden = true;
tsbCreateAddon.Enabled = !Program.WhitelistOverridden;
MessageBox.Show("Restrictions disabled.\nPlease browse for the addon to open it again.",
"Addon is corrupted", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Text = "! - SharpGMad";
UpdateStatus("Restrictions disabled by user's request.");
return;
}
}
}
catch (ArgumentException e)
{
Expand All @@ -123,8 +146,8 @@ private void LoadAddon(string path)
UpdateModified();
UpdateStatus("Loaded the addon" + (AddonHandle.CanWrite ? null : " (read-only mode)"));

tsbAddFile.Enabled = AddonHandle.CanWrite;
tsbUpdateMetadata.Enabled = AddonHandle.CanWrite;
tsbAddFile.Enabled = AddonHandle.CanWrite && !Program.WhitelistOverridden;
tsbUpdateMetadata.Enabled = AddonHandle.CanWrite && !Program.WhitelistOverridden;
}
}

Expand All @@ -144,10 +167,11 @@ private void UpdateModified()
}
else
{
this.Text = Path.GetFileName(AddonHandle.AddonPath) + (AddonHandle.CanWrite ? null : " (read-only)") +
this.Text = Path.GetFileName(AddonHandle.AddonPath) + (Program.WhitelistOverridden ? "!" : null) +
(AddonHandle.CanWrite ? null : " (read-only)") +
(AddonHandle.Modified ? "*" : null) + " - SharpGMad";

tsbSaveAddon.Enabled = AddonHandle.CanWrite && AddonHandle.Modified;
tsbSaveAddon.Enabled = AddonHandle.CanWrite && AddonHandle.Modified && (!Program.WhitelistOverridden);
}
}

Expand Down Expand Up @@ -221,7 +245,8 @@ private void UpdateFileList()
foreColor = System.Drawing.SystemColors.ControlText;

tsslStatus.ForeColor = foreColor;
tsslStatus.Text = "[" + DateTime.Now.ToString() + "] " + text;
tsslStatus.Text = (Program.WhitelistOverridden ? "!Cannot modify addons because the whitelist had been overridden! " : null) +
"[" + DateTime.Now.ToString() + "] " + text;
}

/// <summary>
Expand Down Expand Up @@ -279,7 +304,7 @@ private void UnloadAddon()
lstFiles.Items.Clear();
lstFiles.Groups.Clear();

this.Text = "SharpGMad";
this.Text = "SharpGMad" + (Program.WhitelistOverridden ? "!" : null);
tsbSaveAddon.Enabled = false;

if (AddonHandle != null)
Expand Down Expand Up @@ -323,7 +348,7 @@ private void tsmiLegacyExtract_Click(object sender, EventArgs e)

private void tsbAddFile_Click(object sender, EventArgs e)
{
if (AddonHandle == null)
if (AddonHandle == null || Program.WhitelistOverridden)
return;

// If there is no value for file filtering, load a file list
Expand Down Expand Up @@ -390,7 +415,7 @@ private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
{
// Allow remove, export and execution
tsmFileRemove.Visible = true;
tsmFileRemove.Enabled = AddonHandle.CanWrite;
tsmFileRemove.Enabled = AddonHandle.CanWrite && !Program.WhitelistOverridden;

tsmFileExtract.Enabled = true;
tsmFileExtract.Visible = true;
Expand All @@ -404,15 +429,15 @@ private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
if (isExported.Count() == 0)
{
// Export is the file is not exported
tsmFileExportTo.Enabled = AddonHandle.CanWrite;
tsmFileExportTo.Enabled = AddonHandle.CanWrite && !Program.WhitelistOverridden;
tsmFilePull.Enabled = false;
tsmFileDropExport.Enabled = false;
}
else
{
// Pull (applicable if the file is changed) and drop
tsmFileExportTo.Enabled = false;
tsmFilePull.Enabled = isExported.First().Modified && AddonHandle.CanWrite;
tsmFilePull.Enabled = isExported.First().Modified && AddonHandle.CanWrite && !Program.WhitelistOverridden;
tsmFileDropExport.Enabled = true;
}

Expand All @@ -426,7 +451,7 @@ private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
else if (((System.Windows.Forms.ListView)sender).SelectedItems.Count > 1)
{
// Multiple files support remove, extract, but no exec and export-related stuff
tsmFileRemove.Enabled = true;
tsmFileRemove.Enabled = !Program.WhitelistOverridden;
tsmFileRemove.Visible = true;

tsmFileExtract.Enabled = true;
Expand Down Expand Up @@ -501,7 +526,7 @@ private void lstFiles_KeyDown(object sender, KeyEventArgs e)

private void tsmFileRemove_Click(object sender, EventArgs e)
{
if (!AddonHandle.CanWrite)
if (!AddonHandle.CanWrite || Program.WhitelistOverridden)
return;

if (lstFiles.SelectedItems.Count == 1)
Expand Down Expand Up @@ -599,7 +624,7 @@ private void tsmFileRemove_Click(object sender, EventArgs e)

private void tsbUpdateMetadata_Click(object sender, EventArgs e)
{
if (!AddonHandle.CanWrite)
if (!AddonHandle.CanWrite || Program.WhitelistOverridden)
return;

// Use a toggle mechanism to enable and disable the changing of metadata
Expand Down Expand Up @@ -708,7 +733,7 @@ private void tsbDiscardMetadataChanges_Click(object sender, EventArgs e)

private void tsbSaveAddon_Click(object sender, EventArgs e)
{
if (!AddonHandle.CanWrite)
if (!AddonHandle.CanWrite || Program.WhitelistOverridden)
return;

if (!tsbUpdateMetadata.Checked)
Expand Down Expand Up @@ -745,7 +770,7 @@ private void tsbSaveAddon_Click(object sender, EventArgs e)

private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (AddonHandle is RealtimeAddon && AddonHandle.Modified)
if (AddonHandle is RealtimeAddon && AddonHandle.Modified && !Program.WhitelistOverridden)
{
DialogResult yesClose = MessageBox.Show("Save the addon before quitting?",
Path.GetFileName(AddonHandle.AddonPath), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
Expand Down Expand Up @@ -774,8 +799,14 @@ private void Main_FormClosing(object sender, FormClosingEventArgs e)

private void tsbCreateAddon_Click(object sender, EventArgs e)
{
if (Program.WhitelistOverridden)
{
tsbCreateAddon.Enabled = !Program.WhitelistOverridden;
return;
}

DialogResult dropChanges = new DialogResult();
if (AddonHandle is RealtimeAddon && AddonHandle.Modified)
if (AddonHandle is RealtimeAddon && AddonHandle.Modified && !Program.WhitelistOverridden)
{
dropChanges = MessageBox.Show("Open an another addon without saving the current one?\nYou'll lose the changes.",
"Addon already open", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
Expand Down Expand Up @@ -823,7 +854,7 @@ private void tsbCreateAddon_Click(object sender, EventArgs e)

private void tsmFileExportTo_Click(object sender, EventArgs e)
{
if (!AddonHandle.CanWrite)
if (!AddonHandle.CanWrite || Program.WhitelistOverridden)
return;

if (lstFiles.FocusedItem != null)
Expand Down Expand Up @@ -1046,7 +1077,7 @@ private void tsbPullAll_Click(object sender, EventArgs e)
/// The exported path is known automatically.</param>
private void PullFile(string filename)
{
if (!AddonHandle.CanWrite)
if (!AddonHandle.CanWrite || Program.WhitelistOverridden)
return;

try
Expand Down
6 changes: 6 additions & 0 deletions SharpGMad/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace SharpGMad
/// </summary>
class Program
{
// HACK: This has been just tied into the system to fix opening of illegal GMAs
/// <summary>
/// Indicates whether the whitelist was overridden by an illegal action.
/// </summary>
public static bool WhitelistOverridden = false;

#if WINDOWS
/// <summary>
/// External method to find a pointer for an attached console window.
Expand Down
4 changes: 2 additions & 2 deletions SharpGMad/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.2.1")]
[assembly: AssemblyFileVersion("1.1.2.1")]
[assembly: AssemblyVersion("1.1.2.3")]
[assembly: AssemblyFileVersion("1.1.2.3")]
10 changes: 9 additions & 1 deletion SharpGMad/RealtimeAddon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static RealtimeAddon Load(string filename, bool readOnly = false)
throw new FileNotFoundException("The specified file " + filename + " does not exist.");
}

FileStream fs;
FileStream fs = null;
try
{
if (!readOnly)
Expand All @@ -145,6 +145,9 @@ public static RealtimeAddon Load(string filename, bool readOnly = false)
}
catch (IOException)
{
if (fs != null)
fs.Dispose();

throw;
}

Expand All @@ -155,10 +158,12 @@ public static RealtimeAddon Load(string filename, bool readOnly = false)
}
catch (IOException)
{
fs.Dispose();
throw;
}
catch (ReaderException)
{
fs.Dispose();
throw;
}

Expand All @@ -169,14 +174,17 @@ public static RealtimeAddon Load(string filename, bool readOnly = false)
}
catch (ArgumentException)
{
fs.Dispose();
throw;
}
catch (WhitelistException)
{
fs.Dispose();
throw;
}
catch (IgnoredException)
{
fs.Dispose();
throw;
}

Expand Down
Loading

0 comments on commit 46a3d3d

Please sign in to comment.