Skip to content

Instantly share code, notes, and snippets.

@ShaneGowland
Created December 15, 2015 05:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShaneGowland/4a13b4c8fde9ff8f6ab1 to your computer and use it in GitHub Desktop.
Save ShaneGowland/4a13b4c8fde9ff8f6ab1 to your computer and use it in GitHub Desktop.
“Intermediary” executable file that can easily be set as the default associated program for filetypes that then passes the file along to Atom
Module Module1
Sub Main()
'Get the directory path
Dim exe_path As String = (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\atom\")
'Variable for the highest version
Dim highest_version As New Version("0.0.1")
'Variable for the directory storing the highest version
Dim highest_ver_dir As String = ""
Try
'Iterate through the directory
For Each foundFolder As String In IO.Directory.GetDirectories(exe_path, "*")
'Look only for app directories
If foundFolder.Replace(exe_path, "").StartsWith("app-") Then
'Get the version string
Dim this_version As String = foundFolder.Replace(exe_path & "app-", "")
Dim new_version As New Version(this_version)
'Compare the version
If new_version.CompareTo(highest_version) > 0 Then
highest_version = new_version
highest_ver_dir = foundFolder
End If
End If
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
'Get the filepath to the highest version exe
Dim atom_exe As String = highest_ver_dir & "\atom.exe"
Try
Process.Start(atom_exe, My.Application.CommandLineArgs(0))
Catch ex As Exception
Console.Write(ex.Message)
End Try
End Sub
End Module
@VPenkov
Copy link

VPenkov commented Jan 28, 2016

Hi,

Here's a modification that would allow opening files which have names containing spaces

Module Module1

    Sub Main()

        'Get the directory path
        Dim exe_path As String = (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\atom\")

        'Variable for the highest version
        Dim highest_version As New Version("0.0.1")

        'Variable for the directory storing the highest version
        Dim highest_ver_dir As String = ""

        Try

            'Iterate through the directory
            For Each foundFolder As String In IO.Directory.GetDirectories(exe_path, "*")

                'Look only for app directories
                If foundFolder.Replace(exe_path, "").StartsWith("app-") Then

                    'Get the version string
                    Dim this_version As String = foundFolder.Replace(exe_path & "app-", "")
                    Dim new_version As New Version(this_version)


                    'Compare the version
                    If new_version.CompareTo(highest_version) > 0 Then

                        highest_version = new_version
                        highest_ver_dir = foundFolder

                    End If

                End If

            Next

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try

        'Get the filepath to the highest version exe
        Dim atom_exe As String = highest_ver_dir & "\atom.exe"
        Dim cmd_arguments = Environment.GetCommandLineArgs()
        Try
            Process.Start(atom_exe, String.Format("""{0}""", cmd_arguments(1)))
        Catch ex As Exception
            Console.Write(ex.Message)
        End Try

    End Sub

End Module

Credits to @Bloodb0ne.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment