Game Launcher

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 21 Antworten in diesem Thema. Der letzte Beitrag () ist von ThuCommix.

    Game Launcher

    Hallo liebe community

    Ich bin neu in VB und wollte mir einen Dayz Launcher erstellen.
    Nun habe ich ein Großes Problem das ich mit meinem low wissen nicht hinbekomme :D.

    Ein kollege hat mir eine Batch datei zum joinen auf unseren server erstellt die enthaltene daten muss ich jetzt irgendwie in den launcher einbinden.
    Aber nicht jeder hat Dayz auf den standart pfad installiert.
    Ich habe es hinbekommen das durch drücken vom Button "browse", den Pfad in die textbox gelegt wird nur muss dies auch gespeichert werden damit man es nicht beim jeden start neu suchen muss. ( die code habe ich von Youtube also nichts aus dem kopf soweit bin ich nicht :). )

    Hier der Code von der Batch datei:

    Quellcode

    1. set arma2oapath=C:\Program Files (x86)\Steam\steamapps\common\arma 2 operation arrowhead
    2. set arma2path=C:\Program Files (x86)\Steam\steamapps\common\Arma 2
    3. set IP=00.000.000.00
    4. set PORT=2302
    5. set MODS=@DayzOverwatch;@DayZ_Epoch;@DayZ_Epoch_Server; :: DO NOT EDIT THE LINES BELOW
    6. start "" "%arma2oapath%\ArmA2OA_BE.exe" 0 0 -skipintro -mod=%MODS% -noSplash -noFilePatching -world=empty -connect=%IP% -port=%PORT% "-mod=%arma2path%;expansion;" @exit


    ist das irgendwie machbar ?


    So sollte es dann in etwa aussehen:
    Wenn jmd tipps zum desgin hat gerne höre ich zu.

    Bedanke mich schonmal im vorraus :)


    MfG MRBD69

    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „MRBD69“ ()

    Nicht die batch datei sondern die "ArmA2OA_BE.exe" mit den entsprechenden Parametern.
    Ist im Link oben aber auch so beschrieben...

    C#-Quellcode

    1. ​Process P = new Process();
    2. P.StartInfo.FileName = "notepad.exe";
    3. // Hier die Parameter angeben
    4. P.StartInfo.Arguments = "Test.txt";
    5. P.Start();


    MFG
    :D ah ok jetzt verstehe ich es aber ich bekomme von vb blau unterschtrichene fehler.

    ich glaub ich hab den falschen code angegeben. wie finde ich herraus welches ich habe c#, c++, VB.net oder vb6 gibt es da unterschiede im code ?

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „MRBD69“ ()

    habe so weit hinbekommen die .exe wird mit parameters gestartet und den dateipfad kann man nun auch selber wählen.

    Nun soweit so gut, aber trozdem fehlt etwas irgendwie sagt mir jedes mal das game das ich nicht joinen kann wegen "Sie können diese mission nicht spielen/bearbeiten da sie auf heruntergelad".
    Kennt sich jmd mit DayZ aus ?

    Haben nen eigenen Server mit der Overpoch mod ( Epoch mit Overwatch)
    mit "DayZ Launcher" kann man den server joinen.


    Habe grad gemerkt das wir auch von arma2 die expansion laden müssen nur weis ich nicht wie?

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „MRBD69“ ()

    mit dem originalen Dayz Launcher funktioniert es ja zu joinen.
    Aber wir möchten halt von clan einen extra launcher erstellen, weil manche den server nicht im originalen Dayz Launcher finden,
    und es sieht halt genial aus wenn da unser Clan name steht mit unseren aktuellen server news.

    Problem ist einfach das ich nicht genau weiß wie der Originale DayZ Launcher Funktioniert, welche daten er von welchem server nimmt und wie er das startet.
    wie gesagt bin neu im coden HTML Und Photoshop kenne ich mich mittlerweiler gut aus. :D

    Update funktion möchte ich auch später hinzüfugen damit auch gleich die mods runtergeladen werden. ( spricht 1 klickt und man joint wie beim Wow Launcher)
    Aber solange es nicht mit dem joinen ansich funktioniert kann ich das weiter machen vergessen hat dann kein sinn mehr :D.

    die meisten die das spielen müssten die mods haben bzw. es gibt jede menge anleitungen.An mod files liegt es nicht da alle im steam liegen und ich mit dem Originalen launcher den server joinen kann.
    Die Umgebungsvariablen werden ja auch weiterhin vom Prozess benötigt, egal ob der nun über den Batch oder über ein Program gestartet wird.
    Im Batch sind sie gesetzt worden, in den Beispielen hier nicht.
    Mein "Code" ist auch nicht getestet und nur als Hinweis gedacht.

    VB.NET-Quellcode

    1. Environment.SetEnvironmentVariable("arma2oapath", "C:\Program Files (x86)\Steam\steamapps\common\arma 2 operation arrowhead", EnvironmentVariableTarget.Process)
    2. Environment.SetEnvironmentVariable("arma2path", "C:\Program Files (x86)\Steam\steamapps\common\Arma 2", EnvironmentVariableTarget.Process)
    3. Environment.SetEnvironmentVariable("IP", "00.000.000.00", EnvironmentVariableTarget.Process)
    4. Environment.SetEnvironmentVariable("PORT", "2302", EnvironmentVariableTarget.Process)
    5. Environment.SetEnvironmentVariable("MODS", "@DayzOverwatch;@DayZ_Epoch;@DayZ_Epoch_Server;", EnvironmentVariableTarget.Process)
    6. Dim P As New Process()
    7. P.StartInfo.FileName = "%arma2oapath%\ArmA2OA_BE.exe"
    8. P.StartInfo.Arguments = "0 0 -skipintro -mod=%MODS% -noSplash -noFilePatching -world=empty -connect=%IP% -port=%PORT% -Mod=%arma2path%;expansion; @exit"
    9. P.Start()
    Ich bin Anfänger, nehme aber gerne verbessungs tipps an.
    Hier der Code, hoffe ihr erschlagt mich jetzt nicht :D

    Spoiler anzeigen

    Quellcode

    1. ​Public Class Form1
    2. Private Sub Button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
    3. Button1.BackgroundImage = My.Resources.Startover
    4. End Sub
    5. Private Sub Button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
    6. Button1.BackgroundImage = My.Resources.Start
    7. End Sub
    8. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    9. Me.Close()
    10. End Sub
    11. Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    12. If (e.Button = Windows.Forms.MouseButtons.Left) Then
    13. Me.Capture = False
    14. Me.WndProc(Message.Create(Me.Handle, &HA1, CType(&H2, IntPtr), IntPtr.Zero))
    15. Else : End If
    16. End Sub
    17. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    18. Dim p As New ProcessStartInfo
    19. p.FileName = (TextBox2.Text) 'Apostrophes in a file path? eek
    20. p.Arguments = My.Resources.parameter
    21. p.WindowStyle = ProcessWindowStyle.Normal 'can be hidden
    22. Process.Start(p)
    23. End Sub
    24. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    25. Process.Start("https://www.youtube.com/channel/UCumf00MYH63CxLg449cz9gA")
    26. End Sub
    27. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    28. Process.Start("https://www.facebook.com/ponglenisesports")
    29. End Sub
    30. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    31. Process.Start("http://www.twitch.tv/apecraft")
    32. End Sub
    33. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    34. Dim myFileDlog As New OpenFileDialog()
    35. 'look for files in the c drive
    36. myFileDlog.InitialDirectory = "c:\"
    37. 'specifies what type of data files to look for
    38. myFileDlog.Filter = "All Files (*.*)|*.*" & _
    39. "|Data Files (*.exe)|*.exe"
    40. 'specifies which data type is focused on start up
    41. myFileDlog.FilterIndex = 2
    42. 'Gets or sets a value indicating whether the dialog box restores the current directory before closing.
    43. myFileDlog.RestoreDirectory = True
    44. 'seperates message outputs for files found or not found
    45. If myFileDlog.ShowDialog() = _
    46. DialogResult.OK Then
    47. If Dir(myFileDlog.FileName) <> "" Then
    48. MsgBox("File Exists: " & _
    49. myFileDlog.FileName, _
    50. MsgBoxStyle.Information)
    51. Else
    52. MsgBox("File Not Found", _
    53. MsgBoxStyle.Critical)
    54. End If
    55. End If
    56. 'Adds the file directory to the text box
    57. TextBox1.Text = myFileDlog.FileName
    58. My.Settings.Path1 = TextBox1.Text
    59. My.Settings.Save()
    60. My.Settings.Reload()
    61. End Sub
    62. Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
    63. Dim myFileDlog As New OpenFileDialog()
    64. 'look for files in the c drive
    65. myFileDlog.InitialDirectory = "c:\"
    66. 'specifies what type of data files to look for
    67. myFileDlog.Filter = "All Files (*.*)|*.*" & _
    68. "|Data Files (*.exe)|*.exe"
    69. 'specifies which data type is focused on start up
    70. myFileDlog.FilterIndex = 2
    71. 'Gets or sets a value indicating whether the dialog box restores the current directory before closing.
    72. myFileDlog.RestoreDirectory = True
    73. 'seperates message outputs for files found or not found
    74. If myFileDlog.ShowDialog() = _
    75. DialogResult.OK Then
    76. If Dir(myFileDlog.FileName) <> "" Then
    77. MsgBox("File Exists: " & _
    78. myFileDlog.FileName, _
    79. MsgBoxStyle.Information)
    80. Else
    81. MsgBox("File Not Found", _
    82. MsgBoxStyle.Critical)
    83. End If
    84. End If
    85. 'Adds the file directory to the text box
    86. TextBox2.Text = myFileDlog.FileName
    87. My.Settings.Path1 = TextBox2.Text
    88. My.Settings.Save()
    89. My.Settings.Reload()
    90. End Sub
    91. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    92. TextBox1.Text = My.Settings.Path1
    93. TextBox2.Text = My.Settings.Path2
    94. TextBox1.Text = "C:\Program Files (x86)\Steam\steamapps\common\Arma 2\arma2.exe"
    95. TextBox2.Text = "C:\Program Files (x86)\Steam\steamapps\common\Arma 2 Operation Arrowhead\ArmA2OA.exe"
    96. End Sub
    97. Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
    98. Me.WindowState = FormWindowState.Minimized
    99. End Sub
    100. Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    101. WebBrowser1.Document.BackColor = System.Drawing.Color.Transparent
    102. WebBrowser1.Document.ForeColor = Color.Transparent
    103. End Sub
    104. End Class
    Benutz bitte den VB.NET Tag für deinen Code.
    lässt sich dann besser lesen

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub Button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
    3. Button1.BackgroundImage = My.Resources.Startover
    4. End Sub
    5. Private Sub Button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
    6. Button1.BackgroundImage = My.Resources.Start
    7. End Sub
    8. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    9. Me.Close()
    10. End Sub
    11. Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    12. If (e.Button = Windows.Forms.MouseButtons.Left) Then
    13. Me.Capture = False
    14. Me.WndProc(Message.Create(Me.Handle, &HA1, CType(&H2, IntPtr), IntPtr.Zero))
    15. Else : End If
    16. End Sub
    17. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    18. Dim p As New ProcessStartInfo
    19. p.FileName = (TextBox2.Text) 'Apostrophes in a file path? eek
    20. p.Arguments = My.Resources.parameter
    21. p.WindowStyle = ProcessWindowStyle.Normal 'can be hidden
    22. Process.Start(p)
    23. End Sub
    24. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    25. Process.Start("https://www.youtube.com/channel/UCumf00MYH63CxLg449cz9gA")
    26. End Sub
    27. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    28. Process.Start("https://www.facebook.com/ponglenisesports")
    29. End Sub
    30. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    31. Process.Start("http://www.twitch.tv/apecraft")
    32. End Sub
    33. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    34. Dim myFileDlog As New OpenFileDialog()
    35. 'look for files in the c drive
    36. myFileDlog.InitialDirectory = "c:\"
    37. 'specifies what type of data files to look for
    38. myFileDlog.Filter = "All Files (*.*)|*.*" & _
    39. "|Data Files (*.exe)|*.exe"
    40. 'specifies which data type is focused on start up
    41. myFileDlog.FilterIndex = 2
    42. 'Gets or sets a value indicating whether the dialog box restores the current directory before closing.
    43. myFileDlog.RestoreDirectory = True
    44. 'seperates message outputs for files found or not found
    45. If myFileDlog.ShowDialog() = _
    46. DialogResult.OK Then
    47. If Dir(myFileDlog.FileName) <> "" Then
    48. MsgBox("File Exists: " & _
    49. myFileDlog.FileName, _
    50. MsgBoxStyle.Information)
    51. Else
    52. MsgBox("File Not Found", _
    53. MsgBoxStyle.Critical)
    54. End If
    55. End If
    56. 'Adds the file directory to the text box
    57. TextBox1.Text = myFileDlog.FileName
    58. My.Settings.Path1 = TextBox1.Text
    59. My.Settings.Save()
    60. My.Settings.Reload()
    61. End Sub
    62. Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
    63. Dim myFileDlog As New OpenFileDialog()
    64. 'look for files in the c drive
    65. myFileDlog.InitialDirectory = "c:\"
    66. 'specifies what type of data files to look for
    67. myFileDlog.Filter = "All Files (*.*)|*.*" & _
    68. "|Data Files (*.exe)|*.exe"
    69. 'specifies which data type is focused on start up
    70. myFileDlog.FilterIndex = 2
    71. 'Gets or sets a value indicating whether the dialog box restores the current directory before closing.
    72. myFileDlog.RestoreDirectory = True
    73. 'seperates message outputs for files found or not found
    74. If myFileDlog.ShowDialog() = _
    75. DialogResult.OK Then
    76. If Dir(myFileDlog.FileName) <> "" Then
    77. MsgBox("File Exists: " & _
    78. myFileDlog.FileName, _
    79. MsgBoxStyle.Information)
    80. Else
    81. MsgBox("File Not Found", _
    82. MsgBoxStyle.Critical)
    83. End If
    84. End If
    85. 'Adds the file directory to the text box
    86. TextBox2.Text = myFileDlog.FileName
    87. My.Settings.Path1 = TextBox2.Text
    88. My.Settings.Save()
    89. My.Settings.Reload()
    90. End Sub
    91. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    92. TextBox1.Text = My.Settings.Path1
    93. TextBox2.Text = My.Settings.Path2
    94. TextBox1.Text = "C:\Program Files (x86)\Steam\steamapps\common\Arma 2\arma2.exe"
    95. TextBox2.Text = "C:\Program Files (x86)\Steam\steamapps\common\Arma 2 Operation Arrowhead\ArmA2OA.exe"
    96. End Sub
    97. Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
    98. Me.WindowState = FormWindowState.Minimized
    99. End Sub
    100. Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    101. WebBrowser1.Document.BackColor = System.Drawing.Color.Transparent
    102. WebBrowser1.Document.ForeColor = Color.Transparent
    103. End Sub
    104. End Class


    Hast du dir den Post von Dksksm mal angeschaut? villt löst das dein problem schon.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Schangs“ ()

    @MRBD69
    Es wäre vielleicht hilfreich wenn du die komplette Projektmape posten könntest, dann wäre es meiner Meinung nach wesentlich einfacher dir beim Lernen zu helfen.

    Tipp:
    1. Meiner meinung nach ist es immer nervig mit dem My.Resources zu arbeiten.
    2. Du solltest ganz oben (wirklich ganz oben) "Option Sctrict On" schreiben, damit du lernst von Anfang an sauber zu programmieren.
    @BlueSoftware
    0.Die komplette Projektmape heißt was genau ?
    1. Wie meinst du es mit nervig.
    2. hab "Option Strict On" eingefügt.

    @Schanges
    Mach ich habs vorher net gesehen :D

    @Dksksm
    Ich hab deinen code genommen und mit anderen vergliechen und es funktioniert auch teileweiße sehr gut aber,
    Aus irgendeinen grund will er die ArmA 2 Expansion nicht laden. Bekomme ständig die fehler meldung "Addon sauerland requires addon chernarus" die besagt laut recherche
    das die ArmA 2 Expansion nicht geladen werden im ArmA 2 Ordner.
    Nun gibt es auch eine Anleitungen die es behebt aber die kann ich nicht verwenden, da der Fix den Addon ordner verschiebt.

    Ich hab hier mal meinen Code
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Option Strict On
    2. Public Class Form1
    3. Private Sub Button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
    4. Button1.BackgroundImage = My.Resources.Startover
    5. End Sub
    6. Private Sub Button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
    7. Button1.BackgroundImage = My.Resources.Start
    8. End Sub
    9. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    10. Me.Close()
    11. End Sub
    12. Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    13. If (e.Button = Windows.Forms.MouseButtons.Left) Then
    14. Me.Capture = False
    15. Me.WndProc(Message.Create(Me.Handle, &HA1, CType(&H2, IntPtr), IntPtr.Zero))
    16. Else : End If
    17. End Sub
    18. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    19. Environment.SetEnvironmentVariable("arma2path", TextBox1.Text, EnvironmentVariableTarget.Process)
    20. Environment.SetEnvironmentVariable("arma2oapath", TextBox2.Text, EnvironmentVariableTarget.Process)
    21. Environment.SetEnvironmentVariable("IP", "85.131.236.85", EnvironmentVariableTarget.Process)
    22. Environment.SetEnvironmentVariable("PORT", "2302", EnvironmentVariableTarget.Process)
    23. Environment.SetEnvironmentVariable("MODS", "@DayzOverwatch;@DayZ_Epoch;@DayZ_Epoch1051;", EnvironmentVariableTarget.Process)
    24. Dim P As New Process()
    25. P.StartInfo.FileName = TextBox2.Text + "\ArmA2OA_BE.exe"
    26. P.StartInfo.Arguments = "0 0 -skipintro -mod=%MODS% -noSplash -noFilePatching -world=empty -connect=%IP% -port=%PORT% -mod=%arma2path%;expansion; @exit"
    27. P.Start()
    28. ' Process.Start("cmd", "/c echo hallo")
    29. ' Dim p As New System.Diagnostics.Process
    30. ' p.StartInfo.FileName = "E:\My_programme\test\test.exe"
    31. ' p.StartInfo.Arguments = TextBox1.Text & " " & TextBox2.Text
    32. ' p.Start()
    33. ' Process.Start(steam://rungameid/33930//-nosplash -mod=@DayzOverwatch;@DayZ_Epoch; -connect=81.19.211.147:5102)
    34. End Sub
    35. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    36. Process.Start("https://www.youtube.com/channel/UCumf00MYH63CxLg449cz9gA")
    37. End Sub
    38. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    39. Process.Start("https://www.facebook.com/ponglenisesports")
    40. End Sub
    41. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    42. Process.Start("http://www.twitch.tv/apecraft")
    43. End Sub
    44. Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
    45. If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
    46. TextBox1.Text = FolderBrowserDialog1.SelectedPath
    47. End If
    48. My.Settings.Path1 = TextBox2.Text
    49. My.Settings.Save()
    50. My.Settings.Reload()
    51. End Sub
    52. Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
    53. If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
    54. TextBox1.Text = FolderBrowserDialog1.SelectedPath
    55. End If
    56. My.Settings.Path1 = TextBox2.Text
    57. My.Settings.Save()
    58. My.Settings.Reload()
    59. End Sub
    60. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    61. TextBox1.Text = My.Settings.Path1
    62. TextBox2.Text = My.Settings.Path2
    63. TextBox1.Text = "D:\SteamLibrary\steamapps\common\Arma 2"
    64. TextBox2.Text = "D:\SteamLibrary\steamapps\common\Arma 2 Operation Arrowhead"
    65. End Sub
    66. Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
    67. Me.WindowState = FormWindowState.Minimized
    68. End Sub
    69. Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    70. WebBrowser1.Document.BackColor = System.Drawing.Color.Transparent
    71. WebBrowser1.Document.ForeColor = Color.Transparent
    72. End Sub
    73. End Class


    Und hier hab ich den Code vom DayZ Launcher ( Weiß leider nicht welcher Quelltext das ist)

    Spoiler anzeigen
    Hier der Original link sieht man besser github.com/richardbenson/DayZ-…DayZ-Launcher/Launcher.cs

    Visual Basic-Quellcode

    1. using System;using System.Collections.Generic;using System.ComponentModel;using System.Diagnostics;using System.IO;using System.Net;using System.Security.Principal;using System.Text.RegularExpressions;using System.Windows.Forms;using Microsoft.Win32;using SharpCompress.Common;using SharpCompress.Reader;namespace DayZ_Launcher{ public partial class Launcher : Form { string strDefaultCDN = "http://cdn.armafiles.info/latest/"; string strCurrentCDN; string strBasePath;Dictionary<string, string> strArmaOARegLocation = new Dictionary<string, string>() { { "x86", "SOFTWARE\\Bohemia Interactive Studio\\ArmA 2 OA"}, { "x64", "SOFTWARE\\Wow6432Node\\Bohemia Interactive Studio\\ArmA 2 OA" } };Dictionary<string, string> strArmaRegLocation = new Dictionary<string, string>() { { "x86", "SOFTWARE\\Bohemia Interactive Studio\\ArmA 2"}, { "x64", "SOFTWARE\\Wow6432Node\\Bohemia Interactive Studio\\ArmA 2" } };string strSteamRegPath = "SOFTWARE\\Valve\\Steam";Queue<URLToDownload> downloadList = new Queue<URLToDownload>();public Launcher() { InitializeComponent(); }public void Elevate() { //We need Admin for almost everything in here // Needs UAC elevation for webmin to run WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); bool hasAdministrativeRight = principal.IsInRole(WindowsBuiltInRole.Administrator);if (!hasAdministrativeRight) { ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.Verb = "runas"; processInfo.FileName = Application.ExecutablePath; try { Process.Start(processInfo); } catch { Environment.Exit(0); } Environment.Exit(0); } }public void StartUp(object sender, EventArgs e) {//Set the CDN TODO: Make this changeable somehow strCurrentCDN = strDefaultCDN;//Fetch the Arma Path this.strBasePath = GetArmaOAPath(); if (strBasePath == "") { bool bolPathOK = false; while (!bolPathOK) { if (Application.UserAppDataRegistry.GetValue("Arma2Path") != null) { this.strBasePath = Application.UserAppDataRegistry.GetValue("Arma2Path").ToString(); } else {MessageBox.Show("Unable to locate Arma2 install, please select install path (Contains Arma2oa.exe)."); DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { this.strBasePath = folderBrowserDialog1.SelectedPath; } else { MessageBox.Show("DayZ requires Arma2 : Combined Operations"); Environment.Exit(1); } }//Test the path is ok if (File.Exists(strBasePath + @"\arma2oa.exe")) { Application.UserAppDataRegistry.SetValue("Arma2Path", this.strBasePath); bolPathOK = true; } } } lblStatus.Text = "Found Arma2.";//So we know Arma is installed, what about DayZ? UpdateDayZ(); }private void LaunchDayZ() { lblStatus.Text = "DayZ up to date.";//Now Run Arma with the right switches lblStatus.Text = "Starting DayZ..."; Process prcDayZ = new Process();//Detect if beta patch installed bool bolBetaInstalled = Directory.Exists(this.strBasePath + @"\Expansion\beta"); string strArmaPath = GetArmaPath();if (!bolBetaInstalled) { //Is it the Steam version? If so, we need different parameters if (strBasePath.IndexOf("steamapps") > 0) { try { RegistryKey rk = Registry.CurrentUser; RegistryKey subKey = rk.OpenSubKey(strSteamRegPath); if (subKey != null) { prcDayZ.StartInfo.FileName = subKey.GetValue("SteamExe").ToString(); } } catch { MessageBox.Show("Unable to find Steam"); Environment.Exit(0); } prcDayZ.StartInfo.Arguments = "-applaunch 33930 \"-mod=" + strArmaPath + ";EXPANSION;ca;@dayz -world=Chernarus\""; } else { //Run regular Arma prcDayZ.StartInfo.FileName = this.strBasePath + @"\arma2oa.exe"; prcDayZ.StartInfo.Arguments = @"-mod=@dayz -nosplash -world=Chernarus"; } } else { //Run with beta patch //"E:\Game Files\Bohemia Interactive\ArmA 2\Expansion\beta\arma2oa.exe" -beta=Expansion\beta;Expansion\beta\Expansion;@DayZ -nosplash string strArgs = ""; //if (strBasePath.IndexOf("steamapps") > 0) //{ // strArgs += " -mod=" + strArmaPath + ";EXPANSION;ca"; //} strArgs += " -beta=Expansion\\beta;Expansion\\beta\\Expansion;@DayZ -nosplash -world=Chernarus"; prcDayZ.StartInfo.FileName = this.strBasePath + @"\Expansion\beta\arma2oa.exe"; prcDayZ.StartInfo.Arguments = strArgs; prcDayZ.StartInfo.WorkingDirectory = this.strBasePath; }prcDayZ.Start();//Don't need us anymore, give back the precious resources Environment.Exit(0); }private void UpdateDayZ() { //Check or create base directories if (!Directory.Exists(this.strBasePath + @"\@DayZ")) Directory.CreateDirectory(this.strBasePath + @"\@DayZ"); if (!Directory.Exists(this.strBasePath + @"\@DayZ\Addons")) Directory.CreateDirectory(this.strBasePath + @"\@DayZ\Addons");//Fetch the CDN page GetCurrentFileList();//Begin the checking and download DownloadNextFile(); }private void GetCurrentFileList() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strCurrentCDN); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string html = reader.ReadToEnd(); Regex regex = new Regex("<a href=\".*\\.rar\">(?<name>.*)</a>"); MatchCollection matches = regex.Matches(html); if (matches.Count > 0) { foreach (Match match in matches) { if (match.Success) { URLToDownload thisFile = new URLToDownload { URL = strCurrentCDN + match.Groups["name"].ToString(), File = this.strBasePath + @"\@DayZ\" + match.Groups["name"].ToString() }; downloadList.Enqueue(thisFile); } } } } } }//Find where ARMA is installed private string GetArmaPath() { try { RegistryKey rk = Registry.LocalMachine; RegistryKey subKey = rk.OpenSubKey(strArmaRegLocation[GetBitness()]); if (subKey != null) { return subKey.GetValue("MAIN").ToString(); } else return ""; } catch { return ""; } }private string GetArmaOAPath() { try { RegistryKey rk = Registry.LocalMachine; RegistryKey subKey = rk.OpenSubKey(strArmaOARegLocation[GetBitness()]); if (subKey != null) { return subKey.GetValue("MAIN").ToString(); } else return ""; } catch { return ""; } }//What is the bitness of the system private string GetBitness() { switch (IntPtr.Size) { case 4: return "x86"; case 8: return "x64"; default: return "x86"; } }private string GetEtag(string strURL) { if (Application.UserAppDataRegistry.GetValue(strURL) != null) { return Application.UserAppDataRegistry.GetValue(strURL).ToString(); } else { return ""; } }private void SaveEtag(string strUrl, string strETag) { Application.UserAppDataRegistry.SetValue(strUrl, strETag); }private void UpdateStatus(string strMessage) { lblStatus.Invoke((Action)(() => lblStatus.Text = strMessage)); }// Worker thread to grab the file private void DownloadFile(object sender, DoWorkEventArgs e) { URLToDownload args = e.Argument as URLToDownload; // the URL to download the file from string sUrlToReadFileFrom = args.URL; // the path to write the file to string sFilePathToWriteFileTo = args.File;// first, we need to get the exact size (in bytes) of the file we are downloading Uri url = new Uri(sUrlToReadFileFrom); System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); response.Close(); // gets the size of the file in bytes Int64 iSize = response.ContentLength;// keeps track of the total bytes downloaded so we can update the progress bar Int64 iRunningByteTotal = 0;// use the webclient object to download the file using (System.Net.WebClient client = new System.Net.WebClient()) { UpdateStatus("Downloading " + sUrlToReadFileFrom); // open the file at the remote URL for reading using (System.IO.Stream streamRemote = client.OpenRead(new Uri(sUrlToReadFileFrom))) { // using the FileStream object, we can write the downloaded bytes to the file system using (Stream streamLocal = new FileStream(sFilePathToWriteFileTo, FileMode.Create, FileAccess.Write, FileShare.None)) { // loop the stream and get the file into the byte buffer int iByteSize = 0; byte[] byteBuffer = new byte[iSize]; while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0) { // write the bytes to the file system at the file path specified streamLocal.Write(byteBuffer, 0, iByteSize); iRunningByteTotal += iByteSize;// calculate the progress out of a base "100" double dIndex = (double)(iRunningByteTotal); double dTotal = (double)byteBuffer.Length; double dProgressPercentage = (dIndex / dTotal); int iProgressPercentage = (int)(dProgressPercentage * 100);// update the progress bar bgDownloadWorker.ReportProgress(iProgressPercentage); }// clean up the file stream streamLocal.Close(); }// close the connection to the remote server streamRemote.Close(); }//Extract and delete the file UnRarFile(args); } }private void UnRarFile(URLToDownload args) { //Extract the file to the AddOns folder using (Stream stream = File.OpenRead(args.File)) { UpdateStatus("Extracting " + args.File); var reader = ReaderFactory.Open(stream); while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { Console.WriteLine(reader.Entry.FilePath); reader.WriteEntryToDirectory(this.strBasePath + @"\@DayZ\Addons", ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); } } } //Delete the rar File.Delete(args.File); }private void UpdateProgress(object sender, ProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; }private void DownloadComplete(object sender, RunWorkerCompletedEventArgs e) { //Move on to the next file DownloadNextFile(); }private void DownloadNextFile() { if (downloadList.Count > 0) { URLToDownload nextFile = downloadList.Dequeue(); UpdateIfNeeded(nextFile); } else { LaunchDayZ(); } }//Download update file only if needed private bool UpdateIfNeeded(URLToDownload getFile, string strType = "modified") { //Get our stored eTag for this URL string strETag = ""; strETag = GetEtag(getFile.URL);UpdateStatus("Checking " + getFile.URL);try { //Set up a request and include our eTag HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(getFile.URL); request.Method = "GET"; if (strETag != "") { if (strType == "etag") { request.Headers[HttpRequestHeader.IfNoneMatch] = strETag; } else { try { strETag = strETag.Replace("UTC", "GMT"); //Fix for weird servers not sending correct formate datetime request.IfModifiedSince = Convert.ToDateTime(strETag); } catch (Exception e) { MessageBox.Show("Unable to set modified date for URL: " + getFile.URL + "; " + e.Message); } } } //Grab the response, will throw an exception if it's a 304 (not modified) HttpWebResponse response = (HttpWebResponse)request.GetResponse();//We need to check if an elevation is required if (this.strBasePath.IndexOf("Program Files") > 0) Elevate();//Download the file bgDownloadWorker.RunWorkerAsync(getFile); response.Close();//Save the etag if (strType == "etag") { if (response.Headers[HttpResponseHeader.ETag] != null) SaveEtag(getFile.URL, response.Headers[HttpResponseHeader.ETag]); } else { if (response.Headers[HttpResponseHeader.LastModified] != null) SaveEtag(getFile.URL, response.Headers[HttpResponseHeader.LastModified]); }return true; } catch (System.Net.WebException ex) { if (ex.Response != null) { using (HttpWebResponse response = ex.Response as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.NotModified) { //304 means there is no update available UpdateStatus(getFile.URL + " is up to date"); DownloadNextFile(); return false; } else { // Wasn't a 200, and wasn't a 304 so let the log know MessageBox.Show(string.Format("Failed to check " + getFile.URL + ". Error Code: {0}")); return false; } } } else return false; } catch (Exception e) { MessageBox.Show(string.Format("Failed to update " + getFile.URL + ". Error: {0}", e.Message)); return false; } }class URLToDownload { public string URL { get; set; } public string File { get; set; } } }}


    Dort werden die Pfade wie ich sehe von der Registry ausgelesen aber man kann auch selber den Pfad einfügen weil die Registry zb. meinen Steam pfad anzeigt aber nicht meinen Spiele Pfad.


    Hier das Aktuelle Desgin


    Dieser Beitrag wurde bereits 8 mal editiert, zuletzt von „MRBD69“ ()

    Ne bisher nicht danke :D ich versuche die fehler erst selber zu lösen klappt das nicht kommt google in frage klappt das nicht seit ihr gefragt xD. ( ist einfach die beste seite für vb.)

    text oder ini. Hatte es auch zuerst vor aber ich weiß noch nicht wie man bestimmte zeile auslesen kann.
    hatte die parameter erst in .txt.
    Dei dem Code vom DayZ Launcher handelt es sich um C#, ich habe ihn mal durch den Codeconverter gejagt und hier ist das Ergebnis daraus.

    Spoiler anzeigen

    Also keine Garantie ob's so wirklich läuft weil ungetestet.

    Quellcode

    1. Imports System.Collections.Generic
    2. Imports System.ComponentModel
    3. Imports System.Diagnostics
    4. Imports System.IO
    5. Imports System.Net
    6. Imports System.Security.Principal
    7. Imports System.Text.RegularExpressions
    8. Imports System.Windows.Forms
    9. Imports Microsoft.Win32
    10. Imports SharpCompress.Common
    11. Imports SharpCompress.Reader
    12. Namespace DayZ_Launcher
    13. Public Partial Class Launcher
    14. Inherits Form
    15. Private strDefaultCDN As String = "http://cdn.armafiles.info/latest/"
    16. Private strCurrentCDN As String
    17. Private strBasePath As String
    18. Private strArmaOARegLocation As New Dictionary(Of String, String)() From { _
    19. {"x86", "SOFTWARE\Bohemia Interactive Studio\ArmA 2 OA"}, _
    20. {"x64", "SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA"} _
    21. }
    22. Private strArmaRegLocation As New Dictionary(Of String, String)() From { _
    23. {"x86", "SOFTWARE\Bohemia Interactive Studio\ArmA 2"}, _
    24. {"x64", "SOFTWARE\Wow6432Node\Bohemia Interactive Studio\ArmA 2"} _
    25. }
    26. Private strSteamRegPath As String = "SOFTWARE\Valve\Steam"
    27. Private downloadList As New Queue(Of URLToDownload)()
    28. Public Sub New()
    29. InitializeComponent()
    30. End Sub
    31. Public Sub Elevate()
    32. 'We need Admin for almost everything in here
    33. ' Needs UAC elevation for webmin to run
    34. Dim principal As New WindowsPrincipal(WindowsIdentity.GetCurrent())
    35. Dim hasAdministrativeRight As Boolean = principal.IsInRole(WindowsBuiltInRole.Administrator)
    36. If Not hasAdministrativeRight Then
    37. Dim processInfo As New ProcessStartInfo()
    38. processInfo.Verb = "runas"
    39. processInfo.FileName = Application.ExecutablePath
    40. Try
    41. Process.Start(processInfo)
    42. Catch
    43. Environment.[Exit](0)
    44. End Try
    45. Environment.[Exit](0)
    46. End If
    47. End Sub
    48. Public Sub StartUp(sender As Object, e As EventArgs)
    49. 'Set the CDN TODO: Make this changeable somehow
    50. strCurrentCDN = strDefaultCDN
    51. 'Fetch the Arma Path
    52. Me.strBasePath = GetArmaOAPath()
    53. If strBasePath = "" Then
    54. Dim bolPathOK As Boolean = False
    55. While Not bolPathOK
    56. If Application.UserAppDataRegistry.GetValue("Arma2Path") IsNot Nothing Then
    57. Me.strBasePath = Application.UserAppDataRegistry.GetValue("Arma2Path").ToString()
    58. Else
    59. MessageBox.Show("Unable to locate Arma2 install, please select install path (Contains Arma2oa.exe).")
    60. Dim result As DialogResult = folderBrowserDialog1.ShowDialog()
    61. If result = DialogResult.OK Then
    62. Me.strBasePath = folderBrowserDialog1.SelectedPath
    63. Else
    64. MessageBox.Show("DayZ requires Arma2 : Combined Operations")
    65. Environment.[Exit](1)
    66. End If
    67. End If
    68. 'Test the path is ok
    69. If File.Exists(strBasePath & "\arma2oa.exe") Then
    70. Application.UserAppDataRegistry.SetValue("Arma2Path", Me.strBasePath)
    71. bolPathOK = True
    72. End If
    73. End While
    74. End If
    75. lblStatus.Text = "Found Arma2."
    76. 'So we know Arma is installed, what about DayZ?
    77. UpdateDayZ()
    78. End Sub
    79. Private Sub LaunchDayZ()
    80. lblStatus.Text = "DayZ up to date."
    81. 'Now Run Arma with the right switches
    82. lblStatus.Text = "Starting DayZ..."
    83. Dim prcDayZ As New Process()
    84. 'Detect if beta patch installed
    85. Dim bolBetaInstalled As Boolean = Directory.Exists(Me.strBasePath & "\Expansion\beta")
    86. Dim strArmaPath As String = GetArmaPath()
    87. If Not bolBetaInstalled Then
    88. 'Is it the Steam version? If so, we need different parameters
    89. If strBasePath.IndexOf("steamapps") > 0 Then
    90. Try
    91. Dim rk As RegistryKey = Registry.CurrentUser
    92. Dim subKey As RegistryKey = rk.OpenSubKey(strSteamRegPath)
    93. If subKey IsNot Nothing Then
    94. prcDayZ.StartInfo.FileName = subKey.GetValue("SteamExe").ToString()
    95. End If
    96. Catch
    97. MessageBox.Show("Unable to find Steam")
    98. Environment.[Exit](0)
    99. End Try
    100. prcDayZ.StartInfo.Arguments = "-applaunch 33930 ""-mod=" & strArmaPath & ";EXPANSION;ca;@dayz -world=Chernarus"""
    101. Else
    102. 'Run regular Arma
    103. prcDayZ.StartInfo.FileName = Me.strBasePath & "\arma2oa.exe"
    104. prcDayZ.StartInfo.Arguments = "-mod=@dayz -nosplash -world=Chernarus"
    105. End If
    106. Else
    107. 'Run with beta patch
    108. '"E:\Game Files\Bohemia Interactive\ArmA 2\Expansion\beta\arma2oa.exe" -beta=Expansion\beta;Expansion\beta\Expansion;@DayZ -nosplash
    109. Dim strArgs As String = ""
    110. 'if (strBasePath.IndexOf("steamapps") > 0)
    111. '{
    112. ' strArgs += " -mod=" + strArmaPath + ";EXPANSION;ca";
    113. '}
    114. strArgs += " -beta=Expansion\beta;Expansion\beta\Expansion;@DayZ -nosplash -world=Chernarus"
    115. prcDayZ.StartInfo.FileName = Me.strBasePath & "\Expansion\beta\arma2oa.exe"
    116. prcDayZ.StartInfo.Arguments = strArgs
    117. prcDayZ.StartInfo.WorkingDirectory = Me.strBasePath
    118. End If
    119. prcDayZ.Start()
    120. 'Don't need us anymore, give back the precious resources
    121. Environment.[Exit](0)
    122. End Sub
    123. Private Sub UpdateDayZ()
    124. 'Check or create base directories
    125. If Not Directory.Exists(Me.strBasePath & "\@DayZ") Then
    126. Directory.CreateDirectory(Me.strBasePath & "\@DayZ")
    127. End If
    128. If Not Directory.Exists(Me.strBasePath & "\@DayZ\Addons") Then
    129. Directory.CreateDirectory(Me.strBasePath & "\@DayZ\Addons")
    130. End If
    131. 'Fetch the CDN page
    132. GetCurrentFileList()
    133. 'Begin the checking and download
    134. DownloadNextFile()
    135. End Sub
    136. Private Sub GetCurrentFileList()
    137. Dim request As HttpWebRequest = DirectCast(WebRequest.Create(strCurrentCDN), HttpWebRequest)
    138. Using response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
    139. Using reader As New StreamReader(response.GetResponseStream())
    140. Dim html As String = reader.ReadToEnd()
    141. Dim regex As New Regex("<a href="".*\.rar"">(?<name>.*)</a>")
    142. Dim matches As MatchCollection = regex.Matches(html)
    143. If matches.Count > 0 Then
    144. For Each match As Match In matches
    145. If match.Success Then
    146. Dim thisFile As New URLToDownload() With { _
    147. Key .URL = strCurrentCDN & match.Groups("name").ToString(), _
    148. Key .File = Me.strBasePath & "\@DayZ\" & match.Groups("name").ToString() _
    149. }
    150. downloadList.Enqueue(thisFile)
    151. End If
    152. Next
    153. End If
    154. End Using
    155. End Using
    156. End Sub
    157. 'Find where ARMA is installed
    158. Private Function GetArmaPath() As String
    159. Try
    160. Dim rk As RegistryKey = Registry.LocalMachine
    161. Dim subKey As RegistryKey = rk.OpenSubKey(strArmaRegLocation(GetBitness()))
    162. If subKey IsNot Nothing Then
    163. Return subKey.GetValue("MAIN").ToString()
    164. Else
    165. Return ""
    166. End If
    167. Catch
    168. Return ""
    169. End Try
    170. End Function
    171. Private Function GetArmaOAPath() As String
    172. Try
    173. Dim rk As RegistryKey = Registry.LocalMachine
    174. Dim subKey As RegistryKey = rk.OpenSubKey(strArmaOARegLocation(GetBitness()))
    175. If subKey IsNot Nothing Then
    176. Return subKey.GetValue("MAIN").ToString()
    177. Else
    178. Return ""
    179. End If
    180. Catch
    181. Return ""
    182. End Try
    183. End Function
    184. 'What is the bitness of the system
    185. Private Function GetBitness() As String
    186. Select Case IntPtr.Size
    187. Case 4
    188. Return "x86"
    189. Case 8
    190. Return "x64"
    191. Case Else
    192. Return "x86"
    193. End Select
    194. End Function
    195. Private Function GetEtag(strURL As String) As String
    196. If Application.UserAppDataRegistry.GetValue(strURL) IsNot Nothing Then
    197. Return Application.UserAppDataRegistry.GetValue(strURL).ToString()
    198. Else
    199. Return ""
    200. End If
    201. End Function
    202. Private Sub SaveEtag(strUrl As String, strETag As String)
    203. Application.UserAppDataRegistry.SetValue(strUrl, strETag)
    204. End Sub
    205. Private Sub UpdateStatus(strMessage As String)
    206. lblStatus.Invoke(DirectCast(Function() InlineAssignHelper(lblStatus.Text, strMessage), Action))
    207. End Sub
    208. ' Worker thread to grab the file
    209. Private Sub DownloadFile(sender As Object, e As DoWorkEventArgs)
    210. Dim args As URLToDownload = TryCast(e.Argument, URLToDownload)
    211. ' the URL to download the file from
    212. Dim sUrlToReadFileFrom As String = args.URL
    213. ' the path to write the file to
    214. Dim sFilePathToWriteFileTo As String = args.File
    215. ' first, we need to get the exact size (in bytes) of the file we are downloading
    216. Dim url As New Uri(sUrlToReadFileFrom)
    217. Dim request As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
    218. Dim response As System.Net.HttpWebResponse = DirectCast(request.GetResponse(), System.Net.HttpWebResponse)
    219. response.Close()
    220. ' gets the size of the file in bytes
    221. Dim iSize As Int64 = response.ContentLength
    222. ' keeps track of the total bytes downloaded so we can update the progress bar
    223. Dim iRunningByteTotal As Int64 = 0
    224. ' use the webclient object to download the file
    225. Using client As New System.Net.WebClient()
    226. UpdateStatus("Downloading " & sUrlToReadFileFrom)
    227. ' open the file at the remote URL for reading
    228. Using streamRemote As System.IO.Stream = client.OpenRead(New Uri(sUrlToReadFileFrom))
    229. ' using the FileStream object, we can write the downloaded bytes to the file system
    230. Using streamLocal As Stream = New FileStream(sFilePathToWriteFileTo, FileMode.Create, FileAccess.Write, FileShare.None)
    231. ' loop the stream and get the file into the byte buffer
    232. Dim iByteSize As Integer = 0
    233. Dim byteBuffer As Byte() = New Byte(iSize - 1) {}
    234. While (InlineAssignHelper(iByteSize, streamRemote.Read(byteBuffer, 0, byteBuffer.Length))) > 0
    235. ' write the bytes to the file system at the file path specified
    236. streamLocal.Write(byteBuffer, 0, iByteSize)
    237. iRunningByteTotal += iByteSize
    238. ' calculate the progress out of a base "100"
    239. Dim dIndex As Double = CDbl(iRunningByteTotal)
    240. Dim dTotal As Double = CDbl(byteBuffer.Length)
    241. Dim dProgressPercentage As Double = (dIndex / dTotal)
    242. Dim iProgressPercentage As Integer = CInt(Math.Truncate(dProgressPercentage * 100))
    243. ' update the progress bar
    244. bgDownloadWorker.ReportProgress(iProgressPercentage)
    245. End While
    246. ' clean up the file stream
    247. streamLocal.Close()
    248. End Using
    249. ' close the connection to the remote server
    250. streamRemote.Close()
    251. End Using
    252. 'Extract and delete the file
    253. UnRarFile(args)
    254. End Using
    255. End Sub
    256. Private Sub UnRarFile(args As URLToDownload)
    257. 'Extract the file to the AddOns folder
    258. Using stream As Stream = File.OpenRead(args.File)
    259. UpdateStatus("Extracting " & args.File)
    260. Dim reader = ReaderFactory.Open(stream)
    261. While reader.MoveToNextEntry()
    262. If Not reader.Entry.IsDirectory Then
    263. Console.WriteLine(reader.Entry.FilePath)
    264. reader.WriteEntryToDirectory(Me.strBasePath & "\@DayZ\Addons", ExtractOptions.ExtractFullPath Or ExtractOptions.Overwrite)
    265. End If
    266. End While
    267. End Using
    268. 'Delete the rar
    269. File.Delete(args.File)
    270. End Sub
    271. Private Sub UpdateProgress(sender As Object, e As ProgressChangedEventArgs)
    272. progressBar1.Value = e.ProgressPercentage
    273. End Sub
    274. Private Sub DownloadComplete(sender As Object, e As RunWorkerCompletedEventArgs)
    275. 'Move on to the next file
    276. DownloadNextFile()
    277. End Sub
    278. Private Sub DownloadNextFile()
    279. If downloadList.Count > 0 Then
    280. Dim nextFile As URLToDownload = downloadList.Dequeue()
    281. UpdateIfNeeded(nextFile)
    282. Else
    283. LaunchDayZ()
    284. End If
    285. End Sub
    286. 'Download update file only if needed
    287. Private Function UpdateIfNeeded(getFile As URLToDownload, Optional strType As String = "modified") As Boolean
    288. 'Get our stored eTag for this URL
    289. Dim strETag As String = ""
    290. strETag = GetEtag(getFile.URL)
    291. UpdateStatus("Checking " & getFile.URL)
    292. Try
    293. 'Set up a request and include our eTag
    294. Dim request As HttpWebRequest = DirectCast(HttpWebRequest.Create(getFile.URL), HttpWebRequest)
    295. request.Method = "GET"
    296. If strETag <> "" Then
    297. If strType = "etag" Then
    298. request.Headers(HttpRequestHeader.IfNoneMatch) = strETag
    299. Else
    300. Try
    301. strETag = strETag.Replace("UTC", "GMT")
    302. 'Fix for weird servers not sending correct formate datetime
    303. request.IfModifiedSince = Convert.ToDateTime(strETag)
    304. Catch e As Exception
    305. MessageBox.Show("Unable to set modified date for URL: " & getFile.URL & "; " & e.Message)
    306. End Try
    307. End If
    308. End If
    309. 'Grab the response, will throw an exception if it's a 304 (not modified)
    310. Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
    311. 'We need to check if an elevation is required
    312. If Me.strBasePath.IndexOf("Program Files") > 0 Then
    313. Elevate()
    314. End If
    315. 'Download the file
    316. bgDownloadWorker.RunWorkerAsync(getFile)
    317. response.Close()
    318. 'Save the etag
    319. If strType = "etag" Then
    320. If response.Headers(HttpResponseHeader.ETag) IsNot Nothing Then
    321. SaveEtag(getFile.URL, response.Headers(HttpResponseHeader.ETag))
    322. End If
    323. Else
    324. If response.Headers(HttpResponseHeader.LastModified) IsNot Nothing Then
    325. SaveEtag(getFile.URL, response.Headers(HttpResponseHeader.LastModified))
    326. End If
    327. End If
    328. Return True
    329. Catch ex As System.Net.WebException
    330. If ex.Response IsNot Nothing Then
    331. Using response As HttpWebResponse = TryCast(ex.Response, HttpWebResponse)
    332. If response.StatusCode = HttpStatusCode.NotModified Then
    333. '304 means there is no update available
    334. UpdateStatus(getFile.URL & " is up to date")
    335. DownloadNextFile()
    336. Return False
    337. Else
    338. ' Wasn't a 200, and wasn't a 304 so let the log know
    339. MessageBox.Show(String.Format("Failed to check " & getFile.URL & ". Error Code: {0}"))
    340. Return False
    341. End If
    342. End Using
    343. Else
    344. Return False
    345. End If
    346. Catch e As Exception
    347. MessageBox.Show(String.Format("Failed to update " & getFile.URL & ". Error: {0}", e.Message))
    348. Return False
    349. End Try
    350. End Function
    351. Private Class URLToDownload
    352. Public Property URL() As String
    353. Get
    354. Return m_URL
    355. End Get
    356. Set
    357. m_URL = Value
    358. End Set
    359. End Property
    360. Private m_URL As String
    361. Public Property File() As String
    362. Get
    363. Return m_File
    364. End Get
    365. Set
    366. m_File = Value
    367. End Set
    368. End Property
    369. Private m_File As String
    370. End Class
    371. Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T
    372. target = value
    373. Return value
    374. End Function
    375. End Class
    376. End Namespace


    ((Keine Ahnung warum der Code als "Quellcode" angezeigt wird, ich habe die richtigen Tags genommen und es sollte als VB.Net Quellcode angezeigt werden.))

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Dksksm“ ()