Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
另一进程正在使用vb.net文件_Vb.net - Fatal编程技术网

另一进程正在使用vb.net文件

另一进程正在使用vb.net文件,vb.net,Vb.net,所以我很难让这个程序正常运行。其唯一目的是编辑DOSBox Emulator的配置文件。现在,我正在尝试创建它,以便可以获取位于AppData\Local目录中的DOSBox配置文件,编辑它,然后保存它。我可以很容易地解决我目前的问题,在保存文件后,我得到一个错误,这是这个标题;然而,当我这样做的时候,我得到了另一个错误。它沿着无法关闭溪流的路线前进。idk,它实际上不会在VisualStudio中弹出。它真正做的是保存到我试图修改的文件中。我以前从未见过这种情况。我确实让它在一个点上工作,在那

所以我很难让这个程序正常运行。其唯一目的是编辑DOSBox Emulator的配置文件。现在,我正在尝试创建它,以便可以获取位于AppData\Local目录中的DOSBox配置文件,编辑它,然后保存它。我可以很容易地解决我目前的问题,在保存文件后,我得到一个错误,这是这个标题;然而,当我这样做的时候,我得到了另一个错误。它沿着无法关闭溪流的路线前进。idk,它实际上不会在VisualStudio中弹出。它真正做的是保存到我试图修改的文件中。我以前从未见过这种情况。我确实让它在一个点上工作,在那里它正确地保存了没有错误,但是它没有正确地保存设置

Imports System.Environment
Imports Microsoft.Win32
Imports System.Security.Permissions
Imports System.IO

Public Class Form1
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Application.Exit()
End Sub

'String used to check if the correct file is being used in the OpenFileDialog
Dim filePath As String
'String that contains the path to the AppData\Local\ path
Dim DOSBoxDirectory As String = (GetFolderPath(SpecialFolder.LocalApplicationData) & "\DOSBox")
'Dim ConfigFile As String = My.Computer.FileSystem.ReadAllText(DOSBoxDirectory & "\dosbox-0.74").ToString
Dim ConfigFile As String

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    OpenFileDialog1.FileName = ""
    OpenFileDialog1.ShowDialog()
    OpenFileDialog1.Filter = "DOSBox Configuration File|.conf"
    OpenFileDialog1.InitialDirectory = (GetFolderPath(SpecialFolder.ApplicationData) & "\Local\DOSBox\")
    ConfigFile = OpenFileDialog1.OpenFile.ToString
    filePath = OpenFileDialog1.FileName
    If Not filePath.Contains("dosbox-0.74") Then
        MessageBox.Show("An error has occurred. Have you selected the correct file?", "DOSBox Game Switcher")
    Else
        MessageBox.Show("DOSBox Configuration File Successfully Found. Filepath: " & filePath, "DOSBox Game Switcher")
    End If
    OpenFileDialog1.Dispose()
End Sub

'Save the modified configuration file
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
    Dim NewConfigFile As String
    Try
        If radQWERTY.Checked Then
            NewConfigFile = ConfigFile.Replace("keyboardlayout=dv103", "keyboardlayout=us")
        End If
        If radDVORAK.Checked Then
            NewConfigFile = ConfigFile.Replace("keyboardlayout=us", "keyboardlayout=dv103")
        End If
        If radDAGGERFALL.Checked Then
            NewConfigFile = ConfigFile.Replace("MOUNT C C:\DOSGames\Arena\ARENA - freesize 2000", "#MOUNT C C:\DOSGames\Arena\ARENA - freesize 2000")
            NewConfigFile = ConfigFile.Replace("ARENA.BAT", "#ARENA.BAT")
            NewConfigFile = ConfigFile.Replace("#MOUNT C C:\DOSGames\Daggerfall - freesize 2000", "MOUNT C C:\DOSGames\Daggerfall - freesize 2000")
            NewConfigFile = ConfigFile.Replace("#MOUNT D C:\DOSGames\Daggerfall\DFCD -t cdrom -label Daggerfall", "MOUNT D C:\DOSGames\Daggerfall\DFCD -t cdrom -label Daggerfall")
            NewConfigFile = ConfigFile.Replace("#CD DAGGER", "CD DAGGER")
            NewConfigFile = ConfigFile.Replace("#DAGGER.EXE", "DAGGER.EXE")
        End If
        If radARENA.Checked Then
            NewConfigFile = ConfigFile.Replace("#MOUNT C C:\DOSGames\Arena\ARENA - freesize 2000", "MOUNT C C:\DOSGames\Arena\ARENA - freesize 2000")
            NewConfigFile = ConfigFile.Replace("#ARENA.BAT", "ARENA.BAT")
            NewConfigFile = ConfigFile.Replace("MOUNT C C:\DOSGames\Daggerfall - freesize 2000", "#MOUNT C C:\DOSGames\Daggerfall - freesize 2000")
            NewConfigFile = ConfigFile.Replace("MOUNT D C:\DOSGames\Daggerfall\DFCD -t cdrom -label Daggerfall", "#MOUNT D C:\DOSGames\Daggerfall\DFCD -t cdrom -label Daggerfall")
            NewConfigFile = ConfigFile.Replace("CD DAGGER", "#CD DAGGER")
            NewConfigFile = ConfigFile.Replace("DAGGER.EXE", "#DAGGER.EXE")
        End If
        If txtMemSize.Text IsNot "" Then
            NewConfigFile = ConfigFile.Replace("memsize=16", "memsize=" & Val(txtMemSize.Text))
        End If
        If Not radARENA.Checked And Not radDAGGERFALL.Checked Then
            NewConfigFile = ConfigFile.Replace("MOUNT C C:\DOSGames\Arena\ARENA - freesize 2000", "#MOUNT C C:\DOSGames\Arena\ARENA - freesize 2000")
            NewConfigFile = ConfigFile.Replace("ARENA.BAT", "#ARENA.BAT")
            NewConfigFile = ConfigFile.Replace("MOUNT C C:\DOSGames\Daggerfall - freesize 2000", "#MOUNT C C:\DOSGames\Daggerfall - freesize 2000")
            NewConfigFile = ConfigFile.Replace("MOUNT D C:\DOSGames\Daggerfall\DFCD -t cdrom -label Daggerfall", "#MOUNT D C:\DOSGames\Daggerfall\DFCD -t cdrom -label Daggerfall")
            NewConfigFile = ConfigFile.Replace("CD DAGGER", "#CD DAGGER")
            NewConfigFile = ConfigFile.Replace("DAGGER.EXE", "#DAGGER.EXE")
        End If

    Catch ex As Exception
        MessageBox.Show("An Error Has Ocurred: " & ErrorToString())
    End Try

    If Not NewConfigFile = "" Then
        My.Computer.FileSystem.WriteAllText(DOSBoxDirectory & "\dosbox-0.74.conf", NewConfigFile, False)
    End If
End Sub

'Check if ARENA has been checked and ask to install Arena Remapped from Nexus Mods
Private Sub radARENA_CheckedChanged(sender As Object, e As EventArgs) Handles radARENA.CheckedChanged
    Dim result = MessageBox.Show("It is recommended that you get the Arena Remapped mod from Nexus Mods. Would you like to download this mod? It will be automatically installed for you. It messes with DOSBox controls, so when you choose to play Daggerfall it will automatically be uninstalled.", "DOSBox Game Switcher", MessageBoxButtons.YesNo)

    If result = DialogResult.Yes Then
        saveBinaryFile1()
        'UnRar(My.Computer.FileSystem.SpecialDirectories.Temp & "\TES_Arena_Remapped_1_1_5.zip", DOSBoxDirectory)
        'My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.Temp & "\TES_Arena_Remapped_1_1_5.zip")
    End If
End Sub

'Automatically uninstall Arena Remapped if it exists
Private Sub radDAGGERFALL_CheckedChanged(sender As Object, e As EventArgs) Handles radDAGGERFALL.CheckedChanged
    Try
        My.Computer.FileSystem.DeleteFile((DOSBoxDirectory & "mapper.txt"))
        My.Computer.FileSystem.DeleteFile(DOSBoxDirectory & "mapper-0.74.map")
    Catch ex As Exception
    End Try
End Sub

'Used to unpack the Arena Remapped mod
Private Sub UnRar(ByVal WorkingDirectory As String, ByVal filepath As String)

    ' Microsoft.Win32 and System.Diagnostics namespaces are imported

    Dim objRegKey As RegistryKey
    objRegKey = Registry.ClassesRoot.OpenSubKey("WinRAR\Shell\Open\Command")
    ' Windows 7 Registry entry for WinRAR Open Command

    Dim obj As Object = objRegKey.GetValue("")

    Dim objRarPath As String = obj.ToString()
    objRarPath = objRarPath.Substring(1, objRarPath.Length - 7)

    objRegKey.Close()

    Dim objArguments As String
    ' in the following format
    ' " X G:\Downloads\samplefile.rar G:\Downloads\sampleextractfolder\"
    objArguments = " X " & " " & filepath & " " + " " + WorkingDirectory

    Dim objStartInfo As New ProcessStartInfo()
    ' Set the UseShellExecute property of StartInfo object to FALSE
    ' Otherwise the we can get the following error message
    ' The Process object must have the UseShellExecute property set to false in order to use environment variables.
    objStartInfo.UseShellExecute = False
    objStartInfo.FileName = objRarPath
    objStartInfo.Arguments = objArguments
    objStartInfo.WindowStyle = ProcessWindowStyle.Hidden
    objStartInfo.WorkingDirectory = WorkingDirectory & "\"

    Dim objProcess As New Process()
    objProcess.StartInfo = objStartInfo
    objProcess.Start()

End Sub

Sub saveBinaryFile1()
    Dim b() As Byte = My.Resources.TES_Arena_Remapped_1_1_5
    Dim f2 As New FileIOPermission(FileIOPermissionAccess.Read, DOSBoxDirectory)
    f2.AddPathList(FileIOPermissionAccess.Write Or FileIOPermissionAccess.Read, DOSBoxDirectory)
    My.Computer.FileSystem.WriteAllBytes(DOSBoxDirectory, b, False)
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    frmGameDirectories.Show()
End Sub
End Class
我想去掉OpenFileDialog,因为在这一点上它对程序来说是一个巨大的污点。之后,我需要从配置文件中获取文本,然后编辑它,然后保存它。感谢您的帮助。正如你所知,按钮2是我想要摆脱的,而btnSave是例外的来源。这些是重点关注的主要部分

**编辑**


我修正了这个例外,使用了其他帖子的一些一般性建议;但是,程序没有正确编辑文件。它根本不在编辑。ConfigFile=File.ReadAllTextDOSBoxDirectory&\dosbox-0.74.conf ConfigFile再次成为字符串。在btnSave事件过程中,我没有做任何更改,只是添加了上面的代码

,以防其他人遇到我的初始问题,解决方案是使用File.ReadAllTextpath。

可能的重复项我非常确定,如果您制作MCVE…您将自己找到解决方案。要明确的是,MCVE是最小的,完整且可验证的示例。看,我想去掉OpenFileDialog,因为在这一点上它对程序来说是一个巨大的污点。对话框是如何使程序紧张的?