VB.NET自定义游戏启动器“如果”语句错误:

时间:2013-12-11 20:11:22

标签: vb.net visual-studio-2013

最近我一直试图在VB.NET中为我的Java游戏构建一个自定义启动器。 唯一的问题是代码:

Dim appData As String = Environment.GetFolderPath(SpecialFolder.ApplicationData) & "\.ProjectSpideynn\"

Public Async Sub Start_Click(sender As System.Object, e As System.EventArgs) Handles Start.Click
    If File.Exists(appData & "Pulsar\ProjectSpideynn-Pulsar.jar") Then
        Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
        startInfo.FileName = "cmd.exe"
        startInfo.Arguments = "java -Xmx1024M -Xms1024M -jar" & appData & "Pulsar\ProjectSpideynn-Pulsar.jar"
        startInfo.UseShellExecute = True
        Process.Start(startInfo)
    End If
    If Not File.Exists(appData & "Pulsar\ProjectSpideynn-Pulsar.jar") Then
        My.Computer.Network.DownloadFile("*hidden-link*", appData & "\.ProjectSpideynn\Pulsar\ProjectSpideynn-Pulsar.jar")
        Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
        startInfo.FileName = "javaw.exe"
        startInfo.Arguments = "-Xmx1024M -Xms1024M -jar" & appData & "Pulsar\ProjectSpideynn-Pulsar.jar"
        startInfo.UseShellExecute = True
        Process.Start(startInfo)
    End If
End Sub

If Not File.Exists(appData & "Pulsar\ProjectSpideynn-Pulsar.jar") Then My.Computer.Network.DownloadFile("*hidden-link*", appData & "\.ProjectSpideynn\Pulsar\ProjectSpideynn-Pulsar.jar")的错误,我无法弄清楚原因。

错误:`Microsoft.VisualBasic.dll中发生了'System.IO.IOException'类型的异常,但未在用户代码中处理

其他信息:无法完成操作,因为此路径中已存在文件'C:\ Users \ Spideynn \ AppData \ Roaming.ProjectSpideynn \ .ProjectSpideynn \ Pulsar \ ProjectSpideynn-Pulsar.jar'。 任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

试试这个:

问题是你的if是错误的,因为exists()会返回false,所以你有

if not false then

与以下内容相同:

if true then

所以你的陈述是真的,你必须在你的fisrt IF中使用else

If File.Exists(appData & "Pulsar\ProjectSpideynn-Pulsar.jar") Then
    Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
    startInfo.FileName = "cmd.exe"
    startInfo.Arguments = "java -Xmx1024M -Xms1024M -jar" & appData & "Pulsar\ProjectSpideynn-Pulsar.jar"
    startInfo.UseShellExecute = True
    Process.Start(startInfo)
else
My.Computer.Network.DownloadFile("*hidden-link*", appData & "\.ProjectSpideynn\Pulsar\ProjectSpideynn-Pulsar.jar","","",false,100 ,true)
    Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
    startInfo.FileName = "javaw.exe"
    startInfo.Arguments = "-Xmx1024M -Xms1024M -jar" & appData & "Pulsar\ProjectSpideynn-Pulsar.jar"
    startInfo.UseShellExecute = True
    Process.Start(startInfo)
End If

新错误尝试覆盖您的文件。