How to launch UltraEdit using browser using custom URI? (solved)

How to launch UltraEdit using browser using custom URI? (solved)

23
Basic UserBasic User
23

    Jul 14, 2017#1

    Is it possible to modify the command line options to allow an optional "custom URI"?

    This would enable launching UltraEdit from web and email based server logs and automatically go to the line to edit simply by clicking a browser based link with a specified protocol.

    I've manually added the ultraedit: protocol to the Windows registry to launch UltraEdit with UNC file path and line number. It works for me, but UltraEdit reports that the path is invalid because the path is prefixed with ultraedit:.

    Example for a web based hyperlink:

    Code: Select all

    <a href="ultraedit:\\server1\c\www\index.htm/10">Edit index.htm at line 10</a>
    Clicking on this hyperlink currently results in the command line:

    Code: Select all

    "C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" ultraedit:\\server1\c\www\index.htm/10
    The result is an error that states "ultraedit:\\server1\c\www\index.htm/10 contains an invalid path".

    A filter would be needed to be added to UltraEdit's command line to filter the URI prefix.

    NOTE: My registry file looks like this:

    Code: Select all

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\ultraedit]
    @="UltraEdit Protocol"
    "URL Protocol"=""
    "Content Type"="text/plain"
    
    [HKEY_CLASSES_ROOT\ultraedit\DefaultIcon]
    @="\"C:\\Program Files\\IDM Computer Solutions\\UltraEdit\\uedit64.exe\""
    
    [HKEY_CLASSES_ROOT\ultraedit\shell]
    
    [HKEY_CLASSES_ROOT\ultraedit\shell\open]
    
    [HKEY_CLASSES_ROOT\ultraedit\shell\open\command]
    @="\"C:\\Program Files\\IDM Computer Solutions\\UltraEdit\\uedit64.exe\" \"%1\""

    6,686585
    Grand MasterGrand Master
    6,686585

      Jul 15, 2017#2

      This is of course possible using a filter application or script which converts the URI into a "file path\file name/line number".

      I wrote quickly a batch file for this filter task. File path and line number are optional.

      Code: Select all

      @echo off
      if "%~1" == "" goto :EOF
      
      rem Assign first argument to an environment variable.
      set "FileName=%~1"
      
      rem Remove the string ultraedit: from the value.
      set "FileName=%FileName:ultraedit:=%"
      if not defined FileName goto :EOF
      
      rem Replace all slashes by backslashes.
      set "FileName=%FileName:/=\%"
      
      rem Does the string contain nothing else than backslashes?
      if "%FileName:\=%" == "" goto :EOF
      if "%FileName: =%" == "" goto :EOF
      
      rem If file name string ends with a backslash, remove it.
      if "%FileName:~-1%" == "\" set "FileName=%FileName:~0,-1%"
      if not defined FileName goto :EOF
      
      rem If the non empty string does not contain any backslash, start UltraEdit.
      if "%FileName:\=%" == "%FileName%" goto StartUltraEdit
      
      rem Get the string after last backslash in file name string.
      for /F "delims=" %%I in ("%FileName%") do set "LineNumber=%%~nxI"
      
      rem Does this string not consist of only digits, start UltraEdit.
      for /F "delims=0123456789" %%I in ("%LineNumber%") do goto StartUltraEdit
      
      rem Reformat "FilePath\FileName\LineNumber" to "FilePath\FileName/LineNumber".
      for /F "delims=" %%I in ("%FileName%") do set "FileName=%%~dpI"
      set "FileName=%FileName:~0,-1%/%LineNumber%"
      
      :StartUltraEdit
      set "LineNumber="
      start "UltraEdit" "C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" "%FileName%"
      set "FileName="
      
      The batch file was tested with following strings as arguments:

      Code: Select all

      ""
      " "
      index.htm
      //server1/c/www/index.htm
      \\server1\c\www\index.htm\10
      ultraedit:
      ultraedit:/
      ultraedit:\/\/
      ultraedit://server1/c/www/index.htm/
      ultraedit://server1/c/www/index.htm/10
      UltraEdit:\\server1\c\www\index.htm\10
      
      The batch file must be specified in registry instead of uedit64.exe.

      The usage of a batch file as filter results in opening for a short time a console window. Better would be coding the same argument string processing in a Windows GUI executable not opening a window at all.

      If the URIs could contain also a space character which must be encoded as %20 or other encoded characters, it would be definitely better to write an executable for this task than using a simple batch file.

      A combination of just slahes, backslashes and spaces as argument string is currently also not filtered out as invalid file name string, but could be also added to batch file if really needed.
      Best regards from an UC/UE/UES for Windows user from Austria

      23
      Basic UserBasic User
      23

        Jul 15, 2017#3

        I"m using an application server with a custom function to generate the UltraEdit friendly URL, so I'm able to safely assume that all paths will be valid. (We never use spaces in any filenames.)

        The batch script you provided works well as a proxy. (Did you have this before or quickly write it up on the spot for this post?)
        The major downside is the temporary flash of the console window.

        I used Bat To Exe Converter to convert the BAT file to a 64-bit EXE (and run silently) and it worked.

        Thanks!

        I've attached the files that I use. The "reg" file will need to be edited with the path to the "ultraedit_uri.exe" file.
        UltraEdit_URI.zip (49.89 KiB)   48
        UltraEdit URI REG, BAT & EXE Files

          Jul 15, 2017#4

          Hey @Mofi,

          I wish there was some sort of way to upvote a post or mark it as a solution in this forum (like StackOverflow or GitHub does). If so, I'd be giving you a "thumbs up" in many of the posts in the forum. (They don't even have an emoji for a thumbs up.)

          You've been very helpful. Thanks!