0

So I have a big web browser project and everything seems to be working just fine. I have a feature which allows the user to get news about my website when they click a specific button. The way this is supposed to work is it is going to read text out of a txt file in my dropbox and then display that text in a richtextbox in my application.

The way I did is that I simply uploaded a txt file into my Dropbox folder and gave it a name which never changes so as to work with my code , and then I copied the share link of this file and put it inside my code.

Now whenever I want to update my news , all I have to do is to just edit the txt file in my Dropbox folder , keeping the same file name so the link stays the same and doesn't change thus allowing my application to correctly update the news.

I tested this on my Laptop (which I do all the programming on) and it worked great. I tested this on my old desktop PC and it worked great. I had some friends from different countries around the world test this and this where the problem happens ... it worked great for some of them and for the others it failed and gave an error ... (Hostname couldn't be resolved) Not only this makes the news function in my application not useable , but it also makes the auto update function i have not useable as well because it also uses the same method.

Now let's jump into the code and please help find out what the problem is ...

The following are the main code that works on downloading a file from Dropbox:

Private Sub Download_Dropbox(URL As String, FileName As String)
        Dim Data() = HTTP_Get(URL)
        File.WriteAllBytes(FileName, Data)
    End Sub



Private Function HTTP_Get(Page As String) As Byte()
        Dim Request As HttpWebRequest = WebRequest.Create(Page)
        Request.Method = "GET"
        Request.KeepAlive = True
        Request.ContentType = "application/x-www-form-urlencoded"
        Request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
        Request.AllowAutoRedirect = True

        Dim Response As HttpWebResponse = Request.GetResponse()
        Dim Data As Stream = Response.GetResponseStream()
        Dim Bytes() As Byte
        Using Writer As New MemoryStream
            Dim Buffer(&HFFF) As Byte

            Do
                Dim BytesRead As Long = Data.Read(Buffer, 0, Buffer.Length)
                If BytesRead > 0 Then Writer.Write(Buffer, 0, BytesRead) Else Exit Do
            Loop

            Bytes = Writer.ToArray()
        End Using

        Return Bytes
    End Function

and this is the code for the button that tries to update the news (reads a txt file):

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Form1.IsConnectionAvailable = True Then
            Try
                'Download_Dropbox("https://www.dropbox.com/s/8m2apm0x0rh91e0/orbitnews.txt?dl=1", CurDir & "\orbitnews.txt")
                Dim ABC As String
                Dim myWebClient As New System.Net.WebClient
                Dim file As New System.IO.StreamReader(myWebClient.OpenRead("https://www.dropbox.com/s/8m2apm0x0rh91e0/orbitnews.txt?dl=1"))
                ABC = file.ReadToEnd
                file.Close()
                newsshower.Text = ABC
                My.Settings.oldnews = ABC
                dater.Text = (DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))
                My.Settings.newsrefdate = dater.Text
                My.Settings.Save()
                Timer1.Enabled = True
                Label2.Visible = True
                If newsshower.Text.Contains("Click the button below to update your browser now!") Then
                    If newsshower.Text.Contains(Application.ProductVersion) Then
                        My.Settings.newsupdate = False
                        updatetoggler.Visible = False
                    Else
                        updatetoggler.Visible = True
                        My.Settings.newsupdate = True
                        My.Settings.Save()
                    End If
                End If
            Catch ex As Exception
                MsgBox("An error has occured while refreshing news." & vbCrLf & "Please contact customer support and send them the following:" & vbCrLf & ex.ToString & vbCrLf & vbCrLf & "Customer Support E-mail:" & vbCrLf & "omaradoinc@hotmail.com")

            End Try
        Else
            MsgBox("You aren't connected to the internet." & vbCrLf & "Please connect to the internet to be able to refresh the news.")
        End If
    End Sub

and this is the code that downloads files from Dropbox (which shouls happen when the programs works on updating itself):

Public Sub mainupdate()
        Download_Dropbox("https://www.dropbox.com/s/eomar7a70hokm0l/Orbit.exe?dl=1", CurDir & "\Orbit.exe")
        Download_Dropbox("https://www.dropbox.com/s/ij1qceoe5kr6tmp/Orbit.exe.config?dl=1", CurDir & "\Orbit.exe.config")
        Download_Dropbox("https://www.dropbox.com/s/em4mo4lsoswba4p/Orbit.pdb?dl=1", CurDir & "\Orbit.pdb")
        Download_Dropbox("https://www.dropbox.com/s/g0361qpzvq74ge4/Orbit.vshost.exe?dl=1", CurDir & "\Orbit.vshost.exe")
        Download_Dropbox("https://www.dropbox.com/s/o5bbkn72cbs9bo7/Orbit.vshost.exe.config?dl=1", CurDir & "\Orbit.vshost.exe.config")
        Download_Dropbox("https://www.dropbox.com/s/wzsyzjczibwa9sz/Orbit.xml?dl=1", CurDir & "\Orbit.xml")
        Download_Dropbox("https://www.dropbox.com/s/l0ogz6kxrn951zv/OWBV.txt?dl=1", CurDir & "\OWBV.txt")
    End Sub
    Public Sub othersupdate()
        Download_Dropbox("https://www.dropbox.com/s/lyv0kdmpi85rbdp/libzplay.dll?dl=1", CurDir & "\libzplay.dll")
    End Sub
    Public Sub soundsupdate()
        Download_Dropbox("https://www.dropbox.com/s/hfl1vidanwecad4/not.wav?dl=1", CurDir & "\not.wav")
        Download_Dropbox("https://www.dropbox.com/s/cfroifknr8zmnub/pokked.wav?dl=1", CurDir & "\pokked.wav")
        Download_Dropbox("https://www.dropbox.com/s/c73af0a30hxg7gp/screenshotsound.wav?dl=1", CurDir & "\screenshotsound.wav")
        Download_Dropbox("https://www.dropbox.com/s/ps5ztudy9cwvwnl/timerend.wav?dl=1", CurDir & "\timerend.wav")
    End Sub

    Private Sub Download_Dropbox(URL As String, FileName As String)
        Dim Data() = HTTP_Get(URL)
        File.WriteAllBytes(FileName, Data)

    End Sub

and this is the code for IsConnectionAvailable() in Form1 :

Public Function IsConnectionAvailable() As Boolean
        Dim objUrl As New System.Uri("http://www.google.com")
        Dim objWebReq As System.Net.WebRequest
        objWebReq = System.Net.WebRequest.Create(objUrl)
        Dim objresp As System.Net.WebResponse

        Try
            objresp = objWebReq.GetResponse
            objresp.Close()
            objresp = Nothing
            Return True

        Catch ex As Exception
            objresp = Nothing
            objWebReq = Nothing
            Return False
        End Try
    End Function

and this is the whole code for my update client which completely failes to download any files from Dropbox or read text:

Option Explicit On
Imports System.IO
Imports System.Net
Imports System.Net.Sockets

Public Class Form1
    Dim Listener As New TcpListener(8000)
    Dim Client As TcpClient
    Dim CurDir As String = My.Application.Info.DirectoryPath
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        updatecheck()
    End Sub

    Private Sub helper_Click(sender As Object, e As EventArgs) Handles helper.Click
        helpform.Show()
    End Sub
    Public Sub mainupdate()
        Download_Dropbox("https://www.dropbox.com/s/eomar7a70hokm0l/Orbit.exe?dl=1", CurDir & "\Orbit.exe")
        Download_Dropbox("https://www.dropbox.com/s/ij1qceoe5kr6tmp/Orbit.exe.config?dl=1", CurDir & "\Orbit.exe.config")
        Download_Dropbox("https://www.dropbox.com/s/em4mo4lsoswba4p/Orbit.pdb?dl=1", CurDir & "\Orbit.pdb")
        Download_Dropbox("https://www.dropbox.com/s/g0361qpzvq74ge4/Orbit.vshost.exe?dl=1", CurDir & "\Orbit.vshost.exe")
        Download_Dropbox("https://www.dropbox.com/s/o5bbkn72cbs9bo7/Orbit.vshost.exe.config?dl=1", CurDir & "\Orbit.vshost.exe.config")
        Download_Dropbox("https://www.dropbox.com/s/wzsyzjczibwa9sz/Orbit.xml?dl=1", CurDir & "\Orbit.xml")
        Download_Dropbox("https://www.dropbox.com/s/l0ogz6kxrn951zv/OWBV.txt?dl=1", CurDir & "\OWBV.txt")
    End Sub
    Public Sub othersupdate()
        Download_Dropbox("https://www.dropbox.com/s/lyv0kdmpi85rbdp/libzplay.dll?dl=1", CurDir & "\libzplay.dll")
    End Sub
    Public Sub soundsupdate()
        Download_Dropbox("https://www.dropbox.com/s/hfl1vidanwecad4/not.wav?dl=1", CurDir & "\not.wav")
        Download_Dropbox("https://www.dropbox.com/s/cfroifknr8zmnub/pokked.wav?dl=1", CurDir & "\pokked.wav")
        Download_Dropbox("https://www.dropbox.com/s/c73af0a30hxg7gp/screenshotsound.wav?dl=1", CurDir & "\screenshotsound.wav")
        Download_Dropbox("https://www.dropbox.com/s/ps5ztudy9cwvwnl/timerend.wav?dl=1", CurDir & "\timerend.wav")
    End Sub

    Private Sub Download_Dropbox(URL As String, FileName As String)
        Dim Data() = HTTP_Get(URL)
        File.WriteAllBytes(FileName, Data)

    End Sub
    Private Function HTTP_Get(Page As String) As Byte()
        Dim Request As HttpWebRequest = WebRequest.Create(Page)
        Request.Method = "GET"
        Request.KeepAlive = True
        Request.ContentType = "application/x-www-form-urlencoded"
        Request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
        Request.AllowAutoRedirect = True

        Dim Response As HttpWebResponse = Request.GetResponse()
        Dim Data As Stream = Response.GetResponseStream()
        Dim Bytes() As Byte
        Using Writer As New MemoryStream
            Dim Buffer(&HFFF) As Byte

            Do
                Dim BytesRead As Long = Data.Read(Buffer, 0, Buffer.Length)
                If BytesRead > 0 Then Writer.Write(Buffer, 0, BytesRead) Else Exit Do
            Loop

            Bytes = Writer.ToArray()
        End Using

        Return Bytes
    End Function
    Public Function IsConnectionAvailable() As Boolean
        Dim objUrl As New System.Uri("http://www.google.com")
        Dim objWebReq As System.Net.WebRequest
        objWebReq = System.Net.WebRequest.Create(objUrl)
        Dim objresp As System.Net.WebResponse

        Try
            objresp = objWebReq.GetResponse
            objresp.Close()
            objresp = Nothing
            Return True

        Catch ex As Exception
            objresp = Nothing
            objWebReq = Nothing
            Return False
        End Try
    End Function
    Public Sub updatecheck()
        Try
            If IsConnectionAvailable() = True Then
                Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://pastebin.com/wCt79dEc")
                Dim response As System.Net.HttpWebResponse = request.GetResponse()
                Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
                Dim newestversion As String = sr.ReadToEnd()
                Dim fileContents As String
                Try
                    fileContents = My.Computer.FileSystem.ReadAllText(CurDir & "\OWBV.txt")
                    If newestversion.Contains(fileContents) Then
                        updater.Enabled = False
                    Else

                    End If
                Catch ex As Exception
                    MsgBox("Orbit version file not found. Update button disabled." & "You can do one of the following 2 methods to fix this error. (Administrator rights might be required)" & vbCrLf & "1- Please open Orbit and then head to (Settings) , then check the option (Enable Console) and save changes. " & vbCrLf & "2- Open (File) Menu and launch (Browser Console)" & vbCrLf & "3- Type in the following command without the brackets: ( /vfcreate ) and then press Enter on your keyboard." & vbCrLf & "If the process is successful , then please launch the update client again either through Orbit itself or close Orbit and launch it manually by running (OWBUpdater.exe) in the application directory. " & vbCrLf & "If the process isn't successful , then please contact customer support at: omaradoinc@hotmail.com" & vbCrLf & "The other method to fix this error is:" & vbCrLf & "1- Navigate to Orbit Installation directory/folder." & vbCrLf & "2-Create a notepad (.txt file) and name that file the following name without the brackets: (OWBV)" & vbCrLf & "3- Open the file and type Orbit's old version that you have or as instructed by customer support , save the changes." & vbCrLf & "If you fail to fix this error , please contact customer support at:" & vbCrLf & "omaradoinc@hotmail.com")
                    updater.Enabled = False
                End Try
            Else
                updater.Enabled = False
                repairer.Enabled = False
                intnot.Visible = True
                Me.Text = "Orbit Web Browser Update Client  (No Internet connection)"
            End If
        Catch ex As Exception
            MsgBox("An Error Has Occured While Checking For Updates..." & vbCrLf & "This May Happen Because Of a Load On The Server" & vbCrLf & "Please Try Again Later" & vbCrLf & "If The Problems Still Exists Then Please Report This To:" & vbCrLf & "omaradoinc@hotmail.com")
        End Try
    End Sub

    Private Sub updater_Click(sender As Object, e As EventArgs) Handles updater.Click
        Try
            m1.Visible = False
            m2.Visible = False
            progressor.Visible = True
            Me.Enabled = False
            mainupdate()
            Process.Start(CurDir & "\Orbit.exe")
            MsgBox("Orbit was successfully updated to the latest version.")
            Me.Close()
        Catch ex As Exception
            m1.Visible = True
            m2.Visible = True
            progressor.Visible = False
            Me.Enabled = True
            My.Computer.FileSystem.WriteAllText(CurDir & "\errorlog.txt", ex.ToString, True)
            MsgBox("Update failed." & vbCrLf & "A log file was created in the application directory , Please send it to customer support at:" & vbCrLf & "omaradoinc@hotmail.com")
        End Try
    End Sub

    Private Sub repairer_Click(sender As Object, e As EventArgs) Handles repairer.Click
        Try
            m1.Visible = False
            m2.Visible = False
            progressor.Visible = True
            Me.Enabled = False
            othersupdate()
            soundsupdate()
            Process.Start(CurDir & "\Orbit.exe")
            MsgBox("Orbit was successfully repaired.")
            Me.Close()
        Catch ex As Exception
            m1.Visible = True
            m2.Visible = True
            progressor.Visible = False
            Me.Enabled = True
            My.Computer.FileSystem.WriteAllText(CurDir & "\errorlog.txt", ex.ToString, True)
            MsgBox("Repair failed." & vbCrLf & "A log file was created in the application directory , Please send it to customer support at:" & vbCrLf & "omaradoinc@hotmail.com")
        End Try
    End Sub

    Private Sub remover_Click(sender As Object, e As EventArgs) Handles remover.Click
        Try
            Listener.Start()
            m1.Visible = False
            m2.Visible = False
            progressor.Visible = True
            My.Computer.FileSystem.WriteAllText(CurDir & "\uninstcmd.txt", "cmd:/send\performfactoryreset", True)
            Timer1.Enabled = True
            Timer1.Start()
            Process.Start(CurDir & "\Orbit.exe")
            updater.Enabled = False
            repairer.Enabled = False
            remover.Enabled = False
        Catch ex As Exception
            Listener.Stop()
            Timer1.Stop()
            Timer1.Enabled = False
            m1.Visible = True
            m2.Visible = True
            progressor.Visible = False
            MsgBox("Orbit.exe wasn't found." & vbCrLf & "Unable to complete uninstallation.")
        End Try
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim Message As String
        Dim nStart As Integer
        Dim nLast As Integer
        If Listener.Pending = True Then
            Message = ""
            Client = Listener.AcceptTcpClient
            Dim Reader As New StreamReader(Client.GetStream())
            While Reader.Peek > -1
                Message &= Convert.ToChar(Reader.Read()).ToString
            End While
            If Message.Contains("</>") Then
                nStart = InStr(Message, "</>") + 4
                nLast = InStr(Message, "<\>")
                Message = Mid(Message, nStart, nLast - nStart)
            End If
            If Message.Contains("cmd:/send\completedfactoryreset") Then
                Try
                    My.Computer.FileSystem.WriteAllText(CurDir & "\uninstcmd.txt", "Nothing here.", True)
                    MsgBox("Orbit settings have been successfully cleaned." & vbCrLf & "Thanks for using Orbit , This client will now exit and launch the main uninstaller which will completely remove Orbit from your PC." & vbCrLf & "For customer support , Contact: omaradoinc@hotmail.com")
                    Process.Start(CurDir & "\Uninstal.exe")
                    Me.Close()
                Catch ex As Exception
                    MsgBox("Orbit settings have been successfully cleaned." & vbCrLf & "Thanks for using Orbit , This client will now exit and launch the main uninstaller which will completely remove Orbit from your PC." & vbCrLf & "For customer support , Contact: omaradoinc@hotmail.com")
                    Process.Start(CurDir & "\Uninstal.exe")
                    Me.Close()
                End Try
            End If
        End If
    End Sub
End Class

For now I can't remember the line where the error was but i will try to get my friends to retest and get the exact error as i have setup my application with lots of Try Catch blocks and easy ways to grab the errors in txt files and send them to me so it shouldn't be much of a hassle before i can get the full error. For now is there anything that seems out of space or could be improved to work better?

  • This sounds like a DNS issue on the affected systems, and not necessarily an issue in your code. – Greg Aug 06 '18 at 14:40
  • Greg , Is there anything i can do to bypass this error on such systems? I worked hard untill I could provide buttons to add my progrom as exceptions (inbound and outbound rules) in windows firewall or even entirely enable/disable firewall (ofc the user has the choice whether to do that or not) but yea firewall wasn't the problem so i would appreciate if you know any way to beat that issue. Even if it a whole new method to download files or read text from Dropbox or any other website. – Omar Abdelkareem Aug 06 '18 at 19:51
  • The owners of the system(s) would need to troubleshoot their DNS setup. I.e., they should determine why there are unable to lookup 'www.dropbox.com' (assuming it is failing trying to query 'www.dropbox.com'). There may just be an issue with their DNS server(s), or they may be intentionally blocked. – Greg Aug 06 '18 at 20:57

0 Answers0