Showing posts with label Project Explorer. Show all posts
Showing posts with label Project Explorer. Show all posts

Thursday, December 19, 2019

Project Explorer: Automatically Digitally Signing an EXE After Building

When a customer reports a bug, we usually fix it immediately and send them a “hot fix”, which is usually just an updated EXE. Because it doesn’t go through our usual build process, the EXE isn’t digitally signed, which can cause issues on some machines. I created a batch file to sign the EXE but most of the time forget to run it before sending the EXE to the customer. Then it occurred to me I could automate that process using Project Explorer.

I created the following program and added it to the Addins subdirectory of the folder where Project Explorer exists:

lparameters toParameter1, ;
    tuParameter2, ;
    tuParameter3
local laStack[1], ;
    lnRows, ;
    lnI, ;
    lcApp, ;
     lcDescription, ;
    lcCommand, ;
    lcFolder, ;
    loAppRun

* If this is a registration call, tell the addin manager which method we're
* an addin for.

if pcount() = 1
    toParameter1.Method = 'AfterBuildProject'
    toParameter1.Active = .T.
    toParameter1.Name   = 'Sign EXE after building'
    return
endif

* This is an addin call, so if we built an EXE, sign it.

if tuParameter2 = 3
    lnRows = astackinfo(laStack)
    for lnI = 1 to lnRows
        if 'projectexplorerui.vct' $ laStack[lnI, 2]
            lcApp = fullpath('..\projectexplorer.app', laStack[lnI, 2])
        endif 'projectexplorerui.vct' $ laStack[lnI, 2]
    next lnI
    lcDescription = inputbox('Description', 'Description for EXE')
    text to lcCommand textmerge noshow pretext 1 + 2
    "SignToolPath\signtool.exe" sign /fd SHA256 /tr
http://timestamp.digicert.com /td SHA256 /f CertificatePath /d "<<lcDescription>>" /p Password "<<tuParameter3>>"
    endtext
    lcFolder = justpath(tuParameter3)
    loAppRun = newobject('APIAppRun', 'APIAppRun.PRG', lcApp, lcCommand, ;
        lcFolder, 'HID')
     loAppRun.LaunchAppAndWait()
endif tuParameter2 = 3
return .T.

Substitute SignToolPath with the path to SignTool.exe, CertificatePath with the path and name of the certificate file, and Password with the password.

This program is a Project Explorer addin that’s called after a project is built successfully. This code checks whether it was an EXE (we’re not going to sign an APP) and if so, finds the location of Project Explorer so it can use the built-in APIAppRun class to call SignTool.exe to digitally sign the EXE.

Now, whenever I build an EXE in Project Explorer, it’s automatically signed so I don’t have to remember to do it.

Thursday, June 06, 2019

Integrating Project Explorer with Search Utilities

I’ve been using Project Explorer as a replacement for the VFP Project Manager for a couple of years now. However, I recently ran into a gotcha that I need to handle better. Here’s the story.

If you have it configured to do so (and I do), Project Explorer automatically generates the text equivalent of a binary file such as a form or class using whatever conversion tool you’ve specified (I use FoxBin2Prg) when you’re finished editing the item. I rely on this heavily: every day, I’m modifying some class or another, knowing the VC2 file is automatically created so I don’t have to do it manually. Since our source control repository contains only the text equivalents, not the binary files, this is very important.

The build process for Stonefield Query Enterprise Studio, the developer tool for the web version of Stonefield Query, runs on a build server. It pulls from the remote repository, uses FoxBin2PRG to generate binary files from the text equivalents, builds an from the PJX file, and uses Inno Setup to generate a setup executable.

Recently, one of our developers discovered a bug in Studio. It sounded like something I had just fixed, so I couldn’t reproduce it in my copy, but could in the version generated from the build server. I checked the VCX/VCT files from the build server and sure enough, the class had the unfixed bug. I checked my copy: it had the bug fix. Then I looked at the VC2 file on my machine and saw that the bug was still there. But how could that be?

Then I remember how I’d fixed the bug. I opened my project search utility (yes, I’m aware of GoFish and even use it from time to time, but my utility does 99% of what I need and is way faster), searched for some text, double-clicked the class it found, fixed the bug, and closed the Class Designer. The problem is that since even though Project Explorer was open, it wasn’t asked to open the class, so it didn’t know the class had been changed and didn’t call FoxBin2PRG to generate the VC2 file, so the bug still existed in that file and in our repository.

Of course, it was easy to resolve the problem: generate the VC2 file for the class, commit the change, push to the repository, and run the build process again. But I wanted to make sure this didn’t happen again, so I added a new method to Project Explorer: EditFile. It has the same syntax as EDITSOURCE, but when you close the editor, Project Explorer automatically calls FoxBin2PRG if the file is a binary just like it does if you click the Edit button in Project Explorer. Then I edited my project search utility:

if type('_screen.oProjectExplorers') = 'O' and _screen.oProjectExplorers.Count > 0
    loPE = _screen.oProjectExplorers[1]
endif type('_screen.oProjectExplorers') = 'O' ...
do case
* Other code here.
    case FILES.TYPE = FILETYPE_FORM and vartype(loPE) = 'O'
        loPE.EditFile(lcFileName, lnLineNo, justfname(lcFileName), lcMethod)
    case FILES.TYPE = FILETYPE_FORM
        editsource(lcFileName, lnLineNo, justfname(lcFileName), lcMethod)
    case vartype(loPE) = 'O'
        loPE.EditFile(lcFileName, lnLineNo, lcClass, lcMethod)
    otherwise
        editsource(lcFileName, lnLineNo, lcClass, lcMethod)
endcase

So, when I tell my utility to edit a file containing the search text, it either uses EDITSOURCE if Project Explorer isn’t open or it calls Project Explorer’s EditFile method if it is. Problem solved. The latest version of Project Explorer on GitHub has this change.

I haven’t updated GoFish or Code References but posted an issue with both projects in case the developers or someone want to add support for Project Explorer.

Monday, June 04, 2018

Presenting Session on Project Explorer

I’m presenting “Introducing Project Explorer” this Saturday 2018-06-09 at 10:00 EDT for GRAFUG but anyone’s welcome to attend online: https://global.gotomeeting.com/join/884386213. See grafug.com/topics.htm for the description of the session.

Update: a recording of the presentation is available at https://youtu.be/G43sUwYlDJ0

Wednesday, May 09, 2018

Improvements in Project Explorer

Thanks to many suggestions from the Fox community, I’ve made lots of improvements to the Project Explorer VFPX project since I presented it at Southwest Fox in October 2017 and the German DevCon in November 2017.

Creating new classes and forms

When you click the New button in the toolbar for classes, the New Class dialog appears:

clip_image002

It has similar functionality to that dialog in the Project Manager, with these additional features:

  • Based on is set to the name of the selected class if there is one. This makes it easy to subclass an existing class by simply selecting it and clicking the New button.
  • From is set to the selected VCX but it’s a combobox containing the ten most recently used class libraries, so you can select one from the list. Based on adjusts to display the classes in the selected library. The libraries are listed in most recent to least recent order.
  • You can create a new class by subclassing the Based on class or by copying it (the equivalent of dragging a class from one VCX to another and then renaming it in the Project Manager).

To create a form from a form class, right-click the class and choose Create Form from Class, then specify the name and path of the new form in the file dialog that appears.

Performance improvements

  • At startup, the project was opened and closed multiple times in order to get the version control status of all files. That no longer happens.
  • If only the text equivalents of binary files are stored in the repository, Project Explorer no longer closes the project when committing changes to a file or getting the version control status of a file.
  • Rather than having a single TreeView control that’s constantly emptied and reloaded as you change the selected tag, there’s now one TreeView per tag. Selecting a tag the first time loads and displays that TreeView, including getting the version control status of every file in that tag, and hides the other ones; the next time that tag is selected, the TreeView isn’t reloaded but is simply redisplayed. This makes the performance of switching tags in a large project much faster.

Version control improvements

  • Project Explorer now works properly with Git even when TortoiseGit isn’t installed.
  • Support was added for other “binary to text” converters besides FoxBin2PRG; implementing them is left up to others.
  • You can now change the setting of the Binary Files in Repository setting in the Version Control Properties dialog.
  • The shortcut menu now has Convert Binary to Text and Convert Text to Binary functions. This is handy, for example, if you edit the records in a table for which the text equivalent is stored in the repository.
  • Project Explorer now supports FoxBin2PRG configuration settings better.
  • When version control is turned on for a solution, it now automatically detects if a repository folder exists and only prompts the user if one isn’t found.
  • When dragging a class to another VCX, Project Explorer assigns new UNIQUEID values to the members of the new class. This prevents an issue with duplicate values in FoxBin2PRG.

Other changes

  • The Class Library and Class Name labels in the Servers tab of the project properties are now hyperlinked: clicking them takes you to the VCX or class, respectively.
  • If Solution.xml exists in the current folder, it’s opened automatically rather than prompting the user. Also, if there’s only one PJX file in the current folder and no Solution.xml, Project Explorer automatically opens that project and creates a solution file for it.
  • You can now define both the forecolor and backcolor for categories and specify which color is the Category combobox. Also, the solution is reloaded when you close the Category Editor dialog so changes are displayed immediately.
  • You can now edit the OLEPublic and icon properties of a class in Project Explorer without having to use the Class Designer.
  • The shortcut menu now has a Builder function which invokes the same builder or builder dialog you would see in the Project Manager.
  • The shortcut menu for the User and Description editboxes now has a Zoom function that displays a resizable dialog in which you can view or edit the content of the editbox.
  • Pressing Enter in the TreeView control now acts like double-clicking.
  • If you manually close a project, Project Explorer automatically closes when it’s activated.
  • The Refresh button in the toolbar was replaced with a Sort/Filter button. Refresh is now available in the shortcut menu.
  • Clicking the “…” button in the Sort and Filter and Assign Tags dialogs displays the VFP Expression Builder dialog.
  • Project items now have a CategoryName property so you can filter on that rather than the category’s ID number. Also, the Tags property is now a comma-delimited list of tags instead of a collection for easier filtering.
  • There are a couple of new addins. AddWLCHackCXtoShortcutMenu.prg adds a Run HackCX Professional function to the shortcut menu to launch Hack CX Professional (http://www.whitelightcomputing.com/prodhackcxpro.htm). EditViewWithViewEditorPro.prg tells Project Explorer to edit a view using White Light Computing’s ViewEditor Professional (http://www.whitelightcomputing.com/prodvieweditorpro.htm) rather than the VFP View Designer.
  • The Run function now works for classes. For non-form classes, the class is instantiated and added to _SCREEN at position 0, 0. For form classes, the class is instantiated and a reference to it added to _SCREEN.
  • Turn on the new Add and New allow any file type setting in the Options dialog to allow the Add and New functions to display a dialog in which you can choose any file type. Turn it off to only allow a file of the selected type to be chosen; for example, if a form is currently selected, Add and New only allow you to add or create a form.
  • Turn on the Remove unused headers setting in the Options dialog to remove headers that don’t have any items under them in the TreeView, such as “Labels” if there aren’t any labels in the project.
  • Project Explorer can now be installed or updated using the Thor Check for Updates function.
  • Running Project Explorer with “do ProjectExplorer.app with '?'” displays a help message with the parameters you can pass to it.
  • Numerous bugs were fixed.