
Partial Class settings_downloadPD
    Inherits System.Web.UI.Page

    Private _commonFunctions As CommonFunctions = New CommonFunctions()

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim _storeId = Request.QueryString("s")
        Dim _platform = Request.QueryString("p")
        Dim _redirect = "~/" & ConfigurationManager.AppSettings("PrintItStoreDataVirtualDirectory") & "/" & _storeId & "/"
        Dim _windowsPD As String = ""
        Dim _macPD As String = ""

        Dim _directory = ConfigurationManager.AppSettings("PrintItStoreDataPath") & "\" & _storeId

        '_directory = "c:\Sites\www.goprint2.com\storeData\" & _storeId

        If System.IO.Directory.Exists(_directory) = True Then

            'Dim logFile As System.IO.StreamWriter = System.IO.File.CreateText(_directory & "\" & "debug.txt")

            'logFile.WriteLine("[Directory] =  " & _directory)

            Try
                Dim _file As String
                For Each _file In System.IO.Directory.GetFiles(_directory)
                    'logFile.WriteLine("[Find File : ] " & _file)
                    'If (_file.StartsWith(_directory & "\GoPrint2")) Then
                    'logFile.WriteLine("[Extention : ] " & _commonFunctions.GetDocumentName(_file, True, "\\").ToString().Split("\")(5).Split(".")(1))

                    Dim _fileName = _commonFunctions.GetDocumentName(_file, True, "\\")
                    If _fileName.Split(".")(1) = "exe" Then
                        'logFile.WriteLine("[Find Windows PD : ] " & _file)
                        _windowsPD = _fileName
                    End If
                    If _fileName.Split(".")(1) = "dmg" Then
                        'logFile.WriteLine("[Find Mac PD : ] " & _file)
                        _macPD = _fileName
                    End If
                    'End If
                Next _file
            Catch ex As Exception
                'logFile.WriteLine("[EXCEPTION] " & ex.Message)
            Finally
                'logFile.Close()
                'logFile.Dispose()
            End Try


            If _windowsPD = "" And _macPD = "" Then
                Session("ErrorMessage") = Me.GetLocalResourceObject("ErrorMessage")

                Response.Redirect("~/download_error.aspx")
            Else
                If Not _windowsPD Is Nothing Then
                    If _platform = "w" Then _redirect = _redirect & _windowsPD
                End If
                If Not _macPD Is Nothing Then
                    If _platform = "m" Then _redirect = _redirect & _macPD
                End If
                Response.Redirect(_redirect)
            End If
        Else
            Session("ErrorMessage") = Me.GetLocalResourceObject("ErrorMessage")
            Response.Redirect("~/download_error.aspx")
        End If

    End Sub
End Class
