All pastes #809156 Raw Edit

SPM URL Handler

public text v1 · immutable
·published 2007-12-08 08:59 UTC
rendered paste body
Imports System.Text.RegularExpressions
Imports System.XML
Imports IniFile.IniFile
Module Module1

    Sub Main()
        RunPackageManager(My.Application.CommandLineArgs.Item(0))
    End Sub
    Sub RunPackageManager(ByVal QueryURL As String)
        QueryURL.Replace("spm://", "")
        QueryURL.Replace("/", "")
        Dim match As Match = Regex.Match(QueryURL, "spm://(?'rID'.+?)\/\?(?'mode'.+?)=(?'package'.+)", RegexOptions.IgnoreCase)
        Dim RepositoryURL As String = match.Groups("rID").Value
        Dim Mode As String = match.Groups("mode").Value
        Dim PackageName As String = match.Groups("package").Value

        If System.IO.File.Exists("appupdater.ini") = True Then
            If System.IO.File.Exists("appupdater.bak") = True Then
                System.IO.File.Delete("appupdater.bak")
            End If
            System.IO.File.Move("appupdater.ini", "appupdater.bak")
        End If
        Dim AppUpdaterConfig As New IniFile.IniFile("appupdater.ini")
        AppUpdaterConfig.AddSection("global")
        AppUpdaterConfig.AddKey("status", "security, stable, beta", "global")
        AppUpdaterConfig.AddKey("unzip_params", "%i -d %tempdir", "global")
        AppUpdaterConfig.AddKey("http_proxy", "", "global")
        AppUpdaterConfig.AddKey("https_proxy", "", "global")
        AppUpdaterConfig.AddKey("unknown_txt", "cache\unknown.txt", "global")
        AppUpdaterConfig.AddKey("temp_dir", "cache\temp", "global")
        AppUpdaterConfig.AddKey("search_dirs", "${PROGRAMFILES}, ${SYSTEMDRIVE}\perl, ${SYSTEMDRIVE}\python25, ${WINDIR}\system32, ${ALLUSERSPROFILE}\Start Menu, ${USERPROFILE}\Start Menu, C:\Windows\System32, C:\Windows, C:\Windows\System32\Wbem, C:\Progra~1\Common~1\ULEADS~1\MPEG, C:\Program Files\AppUpdater, C:\Program Files\GNU\GUNPG, C:\Program Files\QuickTime\QTSYSTEM\, C:\Program Files\ShadowNET", "global")
        AppUpdaterConfig.AddKey("unzip", "unzip.py", "global")
        AppUpdaterConfig.AddKey("auto_download", "True", "global")
        AppUpdaterConfig.AddKey("reporting", "True", "global")
        AppUpdaterConfig.AddKey("ftp_proxy", "", "global")
        AppUpdaterConfig.AddKey("cache_dir", "cache", "global")
        AppUpdaterConfig.AddKey("auto_install", "True", "global")
        AppUpdaterConfig.AddKey("refresh_expire", "604800", "global")
        AppUpdaterConfig.AddKey("metalink_params", "-M %i -d %cache --allow-overwrite=true", "global")
        AppUpdaterConfig.AddKey("ignore", "", "global")
        AppUpdaterConfig.AddKey("package_lists", "", "global")
        AppUpdaterConfig.AddKey("cmd_prefix", "start /B /WAIT /BELOWNORMAL """"", "global")
        AppUpdaterConfig.AddKey("installed_txt", "cache\installed.txt", "global")
        AppUpdaterConfig.AddKey("index_hour", "2", "global")
        Dim stream As New IO.FileStream("repositories.xml", IO.FileMode.Open, IO.FileAccess.Read)
        Dim document As New XPath.XPathDocument(stream)
        Dim navigator As XPath.XPathNavigator = document.CreateNavigator()
        Dim nodes As XPath.XPathNodeIterator = navigator.Select("/repositories")
        Do While nodes.MoveNext()
            navigator = nodes.Current
            If navigator.MoveToChild("repositoryURL", navigator.NamespaceURI) Then
                If navigator.GetAttribute("name", navigator.NamespaceURI) = RepositoryURL Then
                    Dim Apps_Url = navigator.Value
                    Console.WriteLine(Apps_Url)
                    AppUpdaterConfig.AddKey("apps_xml", Apps_Url + "/apps.xml", "global")
                End If

            End If
        Loop
        AppUpdaterConfig.Save("appupdater.ini")

        AppUpdaterConfig = Nothing
        Console.WriteLine("Executing Package Manager Application...")
        If Mode = "install" Then
            Dim p As New System.Diagnostics.Process
            Dim psi As New System.Diagnostics.ProcessStartInfo("appupdater.exe")
            psi.Arguments = "--install=""" + PackageName + """ --force --no-silent"""
            psi.RedirectStandardOutput = True
            psi.WindowStyle = ProcessWindowStyle.Hidden
            psi.UseShellExecute = False
            p.StartInfo = psi
            p.Start()
            While p.HasExited = False
                Console.WriteLine(p.StandardOutput)
            End While
            p.WaitForExit()



        ElseIf Mode = "remove" Then
            Dim p As New System.Diagnostics.Process
            Dim psi As New System.Diagnostics.ProcessStartInfo("appupdater.exe")
            psi.Arguments = "--remove=""" + PackageName + """ --force --no-silent"""
            psi.RedirectStandardOutput = True
            psi.WindowStyle = ProcessWindowStyle.Hidden
            psi.UseShellExecute = False
            p.StartInfo = psi
            p.Start()
            While p.HasExited = False
                Console.WriteLine(p.StandardOutput)
            End While
            p.WaitForExit()


        End If
        Console.ReadLine()

    End Sub
End Module