AGS Editor

Further development of AGS Editor

Feature Issue: Check for a restrictive Zone Identifier on the help file before opening it

Pages: [1]

morganw

  • AGSer
  • Posts: 213
« on: 01 Oct 2015, 21:39 »
If the Editor was downloaded and extracted from a zip file, the help file may be blocked by the Zone Identifier stored in an NTFS alternate stream. It may be more beneficial to warn users when a potentially restrictive Zone Identifier is present, rather than present them with a potentially blank display in the help file viewer.

In HelpCommandsComponent.cs:
Code: C#
  1.  using System.Runtime.InteropServices;
  2.  using System.Diagnostics;
  3. +using System.Security;
  4. +using System.Security.Policy;

In the CommandClick function:
Code: C#
  1.  else if (!File.Exists(_helpFileName))
  2.  {
  3.      _guiController.ShowMessage("The help file '" + _helpFileName + "' is missing. You may need to reinstall AGS.", MessageBoxIcon.Warning);
  4.  }
  5. +else if (Zone.CreateFromUrl(_helpFileName).SecurityZone != SecurityZone.MyComputer)
  6. +{
  7. +    _guiController.ShowMessage("The help file '" + _helpFileName + "' is restricted by a Zone Identifier.", MessageBoxIcon.Warning);
  8. +}

The wording of such a warning message would probably require more thought than in this example.

As discussed here:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=51050.msg636521905#msg636521905

ChamberOfFear

  • AGSer
  • Posts: 91
« Reply #1 on: 01 Oct 2015, 22:07 »
The second option should have some kind of hint on how to resolve the issue, like the first one does. Something like "Try checking if the file is blocked in the properties of " + _helpFileName

Also, this may be my personal preference but I find that that strings with variables are easier to read if we use "string.Format" instead, or string interpolation, but I'm not sure if Visual Studio 2008 supports that.
Code: C
  1. // string.Format
  2. _guiController.ShowMessage(string.Format("The help file '{0}' is missing. You may need to reinstall AGS.", _helpFileName), MessageBoxIcon.Warning)
  3.  
  4. //String interpolation
  5. _guiController.ShowMessage($"The help file '{_helpFileName}' is missing. You may need to reinstall AGS.", MessageBoxIcon.Warning)
  6.  

Crimson Wizard

  • AGSer
  • Posts: 8,236
« Reply #2 on: 02 Oct 2015, 09:31 »
Does .NET have means to actually unblock the file?
If yes, then we could instead ask user for permission to unblock the file and do so.
Of course, if the Editor is installed in Program Files, then this should be executed as administrator.

Also, this may be my personal preference but I find that that strings with variables are easier to read if we use "string.Format" instead.
I agree, it will be easier to add translations to the Editor, if we ever decide to do that.

Regarding string interpolation, that is something I never heard about before. Unless I am mistaken it is supported only since .NET 4.5.
« Last Edit: 02 Oct 2015, 09:36 by Crimson Wizard »

morganw

  • AGSer
  • Posts: 213
« Reply #3 on: 02 Oct 2015, 18:28 »
There isn't a way to delete it in .NET, but you can call the Win32 function DeleteFile and then Marshal.GetLastWin32Error to see if it failed with "access denied".
To get an elevated delete process I think you must either start a new process or relaunch the whole application.

I'll give it a go if you think it's worth pursuing. I'm guessing a function to delete an alternate stream should go into the utilities class for the Editor?

Crimson Wizard

  • AGSer
  • Posts: 8,236
« Reply #4 on: 02 Oct 2015, 19:25 »
There isn't a way to delete it in .NET, but you can call the Win32 function DeleteFile and then Marshal.GetLastWin32Error to see if it failed with "access denied".
I could have missed something. Why DeleteFile?
I mean, there was a talk about that "alternate stream". Is that stream deleted with DeleteFile?
« Last Edit: 02 Oct 2015, 19:37 by Crimson Wizard »

morganw

  • AGSer
  • Posts: 213
« Reply #5 on: 03 Oct 2015, 02:05 »
If you call DeleteFile and append ":Zone.Identifier" to the end of the path it should just remove the Zone Identifier and leave the file intact. From what I've read the equivalent delete operation in .NET tries to validate the path first, which fails.

morganw

  • AGSer
  • Posts: 213
« Reply #6 on: 03 Oct 2015, 22:29 »
I've got this working where it asks you to unblock the file, and if this fails it asks you if you want to try again with administrative rights.

To get this to work with a UAC prompt I'm launching a second copy of the Editor with an argument that makes it unblock the file and then exit. The user would never be aware the second copy was launched, all they see is the UAC prompt. The two large changes to get this working are:
  • I had to Enable ClickOnce security settings and specify "full trust" for the AGSEditor project. Without this there is no manifest that allows the application to launch with administrative rights
  • The command line arguments are checked very late in the GUI controller (trying to exit gracefully at this point is triggered warnings about saving your game), so I've added an earlier function to check command line arguments right after the programs start, before the GUI is setup
Does this sound like a reasonable approach? The only other option for deleting with a UAC prompt is to call a totally separate program, but the Editor is already running whereas any other application may also be blocked when trying to launch.

Crimson Wizard

  • AGSer
  • Posts: 8,236
« Reply #7 on: 03 Oct 2015, 23:06 »
This sounds like too much work to fix a simple problem :-/.
I do not think that starting Editor for the only reason of running one operation and quit is worth it.
Maybe just tell user that he needs to restart Editor as administrator to fix help file? Perhaps also explain what is going on, and how they may unblock the file themselves.

This is a kind of action that is only required once in a long while. Meanwhile we will add self-extracting zip to distributives and notify people why it is useful, thus decreasing a chance of problem even more.
« Last Edit: 04 Oct 2015, 00:40 by Crimson Wizard »

morganw

  • AGSer
  • Posts: 213
« Reply #8 on: 04 Oct 2015, 17:41 »
It is more complicated than I thought. If you call DeleteFile with P/Invoke it deletes the alternate stream with no problem, but the .NET functions that checks the Zone Security doesn't seem to actually check the file again - it just use the previous value until the Editor has been restarted. I think to implement this properly it would need a whole class of Alternate Stream functions. As you say, it's a lot of work for a little problem so changing the download types makes more sense.

morganw

  • AGSer
  • Posts: 213
« Reply #9 on: 04 Oct 2015, 18:07 »
Actually it's not related to P/Invoke, just unblocking the file manually while the Editor is open has the same problem. So even the simple message box just to warn people isn't guaranteed to be correct. Maybe this is a .NET framework bug.
« Last Edit: 04 Oct 2015, 18:07 by morganw »

morganw

  • AGSer
  • Posts: 213
« Reply #10 on: 06 Oct 2015, 20:30 »

Crimson Wizard

  • AGSer
  • Posts: 8,236
« Reply #11 on: 25 Jan 2016, 14:45 »
Was added to 3.3.5
  • Fixed Version changed from (none) to AGS 3.3.5
  • Status changed from Confirmed to Resolved

Issue updated by Crimson Wizard
« Reply #12 on: 01 Oct 2015, 21:41 »
  • Version changed from Future version to AGS 3.3.5
  • Status changed from New to Confirmed

Issue updated by Crimson Wizard
« Reply #13 on: 21 Jan 2018, 07:20 »
  • Status changed from Resolved to Closed

Pages: [1]

Issue Details

  • Reported
    01 Oct 2015, 21:39
  • Updated
    21 Jan 2018, 07:20
  • View Status
    Public
  • Type
    Feature
  • Status
    Closed
  • Priority
    Normal
  • Version
    AGS 3.3.5
  • Fixed in
    AGS 3.3.5
  • Assigned to
    (none)
  • Category
    User Experience

Tags



Powered by: SMF Project Tools 0.5.4 © Niko Pahajoki 2007-2011