Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class HexEditor
	Inherits System.Windows.Forms.Form
	
	Public itemnum As Short
	Public ItemType As String
    Public itemdata As IO.MemoryStream
	Public itemlen As Integer
	
	
	Public Sub init()
		
		ItemType = App.mapfile.gettype_Renamed(itemnum)
		'itemdata = App.graphics.itemstr(itemnum)
		'itemlen = App.graphics.itemsize(itemnum)
		itemdata = App.graphics.getgitemdata(itemnum)
		itemlen = App.graphics.getgitemsize(itemnum)
		init_contents()
		
	End Sub
	
	Public Sub init_contents()
        Dim i As Integer
		
        Dim s As String = ""
		Dim masked As Integer
		Dim data As Byte
		
		masked = 65536
		s = s & VB.Right(Hex(masked), 4) & " :: "
		For i = 1 To itemlen
			'UPGRADE_ISSUE: MidB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
			'UPGRADE_ISSUE: AscB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
            data = itemdata.ToArray()(i - 1)
			
			If data < 16 Then
				s = s & "0"
			End If
			
			s = s & Hex(data)
			'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			masked = i - 1 And 15
			
			If masked = 15 Then
				s = s & Chr(13) & Chr(10)
				'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				masked = i
				masked = masked + 65536
				s = s & VB.Right(Hex(masked), 4) & " :: "
			Else
				s = s & " "
			End If
		Next 
		Contents.Text = s
		
	End Sub
	Private Sub MaskEdBox1_Change()
		
	End Sub
	
    Private Sub Cancel_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub
	
	'UPGRADE_NOTE: mapfile was upgraded to mapfile_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Private Sub Export_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Export.Click
        Dim sfile As String

        Dim dlg As New SaveFileDialog
        'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
        With dlg
            On Error GoTo canceled
            .Title = "Export"
            'UPGRADE_WARNING: The CommonDialog CancelError property is not supported in Visual Basic .NET. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8B377936-3DF7-4745-AA26-DD00FA5B9BE1"'
            '.CancelError = True
            'UPGRADE_WARNING: MSComDlg.CommonDialog property dlg.Flags was upgraded to dlgSave.OverwritePrompt which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
            .OverwritePrompt = True
            'ToDo: set the flags and attributes of the common dialog control
            'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            .Filter = "*.dat|*.dat|All Files (*.*)|*.*||"
            'UPGRADE_WARNING: Couldn't resolve default property of object mapfile.getname. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            .FileName = CStr((zerostr(itemnum, 4) & " ") + mapfile.getname(itemnum) + (".dat"))
            If .ShowDialog() <> Windows.Forms.DialogResult.OK Then Error 1
            On Error GoTo 0
            'UPGRADE_WARNING: CommonDialog property dlg.FileTitle was upgraded to dlg.FileName which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
            If Len((New System.IO.DirectoryInfo(.FileName)).Name) = 0 Then
                Exit Sub
            End If
            sfile = .FileName
            'curlevel = 0
        End With

        App.graphics.gexport_raw(itemnum, sfile)
        'App.graphics.export_raw itemdata, sfile
canceled:
    End Sub
	
	Private Sub HexEditor_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		
	End Sub
	
	'UPGRADE_NOTE: mapfile was upgraded to mapfile_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
	'UPGRADE_NOTE: graphics was upgraded to graphics_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Private Sub Import_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Import.Click
        Dim f As String
        Dim sfile As String

        Dim dlg As New OpenFileDialog
        'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
        With dlg
            On Error GoTo canceled
            .Title = "Import"
            'UPGRADE_WARNING: The CommonDialog CancelError property is not supported in Visual Basic .NET. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8B377936-3DF7-4745-AA26-DD00FA5B9BE1"'
            '.CancelError = True
            'ToDo: set the flags and attributes of the common dialog control
            'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            .Filter = "*.dat|*.dat|All Files (*.*)|*.*||"
            'UPGRADE_WARNING: Couldn't resolve default property of object mapfile.getname. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            .FileName = CStr((zerostr(itemnum, 4) & " ") + mapfile.getname(itemnum) + (".dat"))
            '.CancelError = True

            If .ShowDialog() <> Windows.Forms.DialogResult.OK Then Error 1
            On Error GoTo 0

            'UPGRADE_WARNING: CommonDialog property dlg.FileTitle was upgraded to dlg.FileName which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
            If Len((New System.IO.DirectoryInfo(.FileName)).Name) = 0 Then
                Exit Sub
            End If
            'curlevel = 0
            'fs = CreateObject("Scripting.FileSystemObject")
            'UPGRADE_WARNING: Couldn't resolve default property of object fs.GetFile. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            f = IO.Path.GetFileName(.FileName)
            sfile = .FileName

            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.import_raw. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            itemlen = graphics.import_raw(itemdata, sfile)
        End With

        init_contents()
canceled:
    End Sub
	
	'UPGRADE_NOTE: mapfile was upgraded to mapfile_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
	'UPGRADE_NOTE: graphics was upgraded to graphics_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Private Sub Ok_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ok.Click
        Dim newtype As String

        'App.graphics.setitemstr itemnum, itemdata
        'App.graphics.setitemsize itemnum, itemlen

        App.graphics.setgitemdata(itemnum, itemdata)
        App.graphics.setgitemsize(itemnum, itemlen)

        'UPGRADE_WARNING: Couldn't resolve default property of object mapfile.gettype. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        newtype = mapfile.gettype_Renamed(itemnum)
        If newtype = "IMG1" Then
            'graphics.reloadgraphic itemnum, 0
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.buildbmp. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.buildbmp(itemnum)
        End If

        Me.Close()
    End Sub
End Class