Skip to content

Commit

Permalink
Merge pull request #23 from aianlinb/beta
Browse files Browse the repository at this point in the history
Some optimizations
  • Loading branch information
Chuanhsing authored Dec 25, 2019
2 parents e19d7c1 + f055317 commit 8b0de83
Show file tree
Hide file tree
Showing 24 changed files with 7,053 additions and 5,927 deletions.
6 changes: 6 additions & 0 deletions DatEditer/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
126 changes: 126 additions & 0 deletions DatEditer/DatEditer.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6601B7A5-54D8-4E39-864C-FA5436FE5E74}</ProjectGuid>
<OutputType>WinExe</OutputType>
<StartupObject>DatEditer.My.MyApplication</StartupObject>
<RootNamespace>DatEditer</RootNamespace>
<AssemblyName>DatEditer</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>WindowsForms</MyType>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>
</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>
</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Data" />
<Import Include="System.Drawing" />
<Import Include="System.Diagnostics" />
<Import Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="DatWrapper.vb" />
<Compile Include="Form1.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.vb">
<DependentUpon>Form1.vb</DependentUpon>
<SubType>Form</SubType>
</Compile>
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
<None Include="My Project\DataSources\Form1.datasource" />
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibDat\LibDat.csproj">
<Project>{8f9fc78e-6181-4447-ac45-56173c16a0fa}</Project>
<Name>LibDat</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>
152 changes: 152 additions & 0 deletions DatEditer/DatWrapper.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Text
Imports LibDat
Imports LibDat.Data

Namespace VisualGGPK
Public Class DatString
Private _data As AbstractData

Public ReadOnly Property DataType As String
Get
Return _data.GetType().ToString().Replace("LibDat.Data.", "")
End Get
End Property

Public ReadOnly Property OffsetStart As Integer
Get
Return _data.Offset
End Get
End Property

Public ReadOnly Property OffsetEnd As Integer
Get
Return _data.Offset + _data.Length
End Get
End Property

Public ReadOnly Property Length As Integer
Get
Return _data.Length
End Get
End Property

Public ReadOnly Property IsUser As Boolean

Public Property NewValue As String
Get
Dim str = TryCast(_data, StringData)
If Not IsNothing(str) Then
Return str.NewValue
Else
Return ""
End If
End Get
Set(value As String)
DirectCast(_data, StringData).NewValue = value
End Set
End Property

Public ReadOnly Property Value As String
Get
Return _data.GetValueString()
End Get
End Property

Public Sub New(Data As AbstractData, isUser As Boolean)
_data = Data
Me.IsUser = isUser
End Sub
End Class

Public Class DatWrapper

Private _datName As String
Private _dat As DatContainer

Public ReadOnly Property RecordInfo As RecordInfo
Get
Return _dat.RecordInfo
End Get
End Property

Public ReadOnly Property DataSectionffset As Long
Get
Return DatContainer.DataSectionOffset
End Get
End Property

Public ReadOnly Property DataSectionDataLength As Long
Get
Return _dat.DataSectionDataLength
End Get
End Property

Public ReadOnly Property Records As List(Of RecordData)
Get
Return _dat.Records
End Get
End Property

Public ReadOnly Property DataEntries As Dictionary(Of Integer, AbstractData)
Get
Return DatContainer.DataEntries
End Get
End Property

Private _dataStrings As New List(Of DatString)
Public ReadOnly Property Strings As List(Of DatString)
Get
Return _dataStrings
End Get
End Property

Public Sub New(fileName As String)
_datName = Path.GetFileNameWithoutExtension(fileName)
Dim fileBytes = File.ReadAllBytes(fileName)
ParseDatFile(New MemoryStream(fileBytes))
End Sub

Public Sub New(inStream As Stream, fileName As String)
_datName = Path.GetFileNameWithoutExtension(fileName)
ParseDatFile(inStream)
End Sub

Private Sub ParseDatFile(inStream As Stream)
Try
_dat = New DatContainer(inStream, _datName)
Dim containerData = DataEntries.ToList()
Dim userStringOffsets = _dat.GetUserStringOffsets()
For Each keyValuePair In containerData
Dim data = keyValuePair.Value
Dim isUser = userStringOffsets.Contains(keyValuePair.Key)
Strings.Add(New DatString(data, isUser))
Next
Catch ex As Exception
Throw New Exception(String.Format("Failed to read dat: {0}", ex.Message), ex)
End Try
End Sub

Public Sub Save(savePath As String)
Try
_dat.Save(savePath)
Catch ex As Exception
Dim errorString As New StringBuilder()
Dim temp = ex
While (temp IsNot Nothing)
errorString.AppendLine(temp.Message)
temp = temp.InnerException
End While
MessageBox.Show(String.Format("Failed to save: {0}", errorString), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
MessageBox.Show(String.Format("Saved '{0}'", savePath), "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Public Function GetCSV() As String
Return _dat.GetCsvFormat()
End Function

End Class
End Namespace
Loading

0 comments on commit 8b0de83

Please sign in to comment.