promote som misc work

This commit is contained in:
yyc12345 2023-02-19 21:59:05 +08:00
parent 44bb2eae02
commit f1477e03da
9 changed files with 157 additions and 172 deletions

View File

@ -1,8 +1,14 @@
import Scripts.VSProp as VSProp import VSProp
import os import os
import sys import sys
# ======================== const define # =========== check work dir ===========
if not os.path.isfile(os.path.join(os.getcwd(), 'README.md')):
print('Error! Please run this script at the root of this repository.')
sys.exit(1)
# =========== const define ===========
build_type_standalone = "standalone" build_type_standalone = "standalone"
build_type_plugin = "plugin" build_type_plugin = "plugin"
@ -68,7 +74,7 @@ valid_vt21_reverse_work_type = (
'doyagu' 'doyagu'
) )
# ======================== assist func # =========== assist func ===========
def get_executable_virtools(vt_ver): def get_executable_virtools(vt_ver):
if vt_ver == '21': if vt_ver == '21':
return 'Dev.exe' return 'Dev.exe'
@ -81,7 +87,7 @@ def get_executable_virtools(vt_ver):
elif vt_ver == '50': elif vt_ver == '50':
return 'devr.exe' return 'devr.exe'
# ======================== requirement get # =========== requirement get ===========
# get basic cfg, such as build type, and vt version # get basic cfg, such as build type, and vt version
while True: while True:
@ -147,8 +153,7 @@ else:
else: else:
break break
# ======================== construct some path # =========== construct some path ===========
# .......todo
# build sqlite related data # build sqlite related data
sqlite_header_path = input_sqlite_header_path sqlite_header_path = input_sqlite_header_path
@ -226,7 +231,7 @@ else:
virtools_lib_path = os.path.join(input_virtools_root_path, 'Sdk/Lib/Win32/Release') virtools_lib_path = os.path.join(input_virtools_root_path, 'Sdk/Lib/Win32/Release')
# ======================== create props # =========== create props ===========
props = VSProp.VSPropWriter() props = VSProp.VSPropWriter()
vcxproj = VSProp.VSVcxprojModifier('./SuperScriptMaterializer/SuperScriptMaterializer.vcxproj') vcxproj = VSProp.VSVcxprojModifier('./SuperScriptMaterializer/SuperScriptMaterializer.vcxproj')
@ -270,7 +275,7 @@ props.AddMacro('VIRTOOLS_MODULE_DEFINE', virtools_module_define)
props.Write2File('./SuperScriptMaterializer/Virtools.props') props.Write2File('./SuperScriptMaterializer/Virtools.props')
vcxproj.Write2File() vcxproj.Write2File()
# ======================== create vt21 props # =========== create vt21 props ===========
# if we are using virtools 2.1. and we use gamepiaynmo as our # if we are using virtools 2.1. and we use gamepiaynmo as our
# reverse library. we need enable project GPVirtoolsStatic and # reverse library. we need enable project GPVirtoolsStatic and

View File

@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "SSDecorator",
"type": "python",
"request": "launch",
"program": "SuperScriptDecorator.py",
"console": "integratedTerminal",
"args": ["-d", "-i", "../example.txt", "-o", "decorate.db"],
"justMyCode": false
}
]
}

View File

@ -1,8 +1,58 @@
import locale import locale, sys, os, shlex
class InputEntry(object):
def __init__(self, data: tuple[str]):
if len(data) != 4:
raise Exception(f"Input syntax error. Require 4 items but got {len(data)}")
self.m_Name: str = data[0]
self.m_VtFile: str = data[1]
self.m_ExportDb: str = data[2]
self.m_EnvDb: str = data[3]
class CustomConfig(object):
def __init__(self):
# encoding list # encoding list
# https://docs.python.org/3/library/codecs.html#standard-encodings # https://docs.python.org/3/library/codecs.html#standard-encodings
database_encoding = locale.getpreferredencoding() self.m_DatabaseEncoding: str = locale.getpreferredencoding()
export_db = "import.txt" self.m_DebugMode = False
decorated_db = "decorate.db"
debug_mode = False self.m_ImportTxt: str = None
self.m_DecoratedDb: str = None
self.m_InputEntries: list[InputEntry] = []
def Regulate(self) -> bool:
# check input and output
if self.m_ImportTxt is None:
print("No input. Decorator exit.")
return False
if not os.path.isfile(self.m_ImportTxt):
print(f'No such input: "{self.m_ImportTxt}"')
return False
if self.m_DecoratedDb is None:
print("No output. Decorator exit.")
return False
if os.path.isdir(self.m_DecoratedDb):
print("Output must be a file.")
return False
# remove result database in debug mode
if self.m_DebugMode and os.path.isfile(self.m_DecoratedDb):
os.remove(self.m_DecoratedDb)
# process input file
try:
with open(self.m_ImportTxt, 'r', encoding='utf-8') as f:
while True:
ln = f.readline()
if ln == '': break
ln.strip()
if ln == '': continue
self.m_InputEntries.append(InputEntry(shlex.split(ln)))
except Exception as ex:
print("Errro when processing input file.")
print(ex)
return True

View File

@ -1,29 +1,51 @@
import sys import sys
value_All = 0 class Prograssbar(object):
value_Now = 0 def __init__(self, filecount: int):
progressbar_span = 2 if (filecount < 0): raise Exception("Progressbar can not hold minus length!")
progressbar_count = int(100/progressbar_span)
def initProgressbar(all): self.__FileCount: int = filecount
global value_Now, value_All self.__FileNow: int = 0
value_All = all self.__ContentCount: int = 0
value_Now = 0 self.__ContentNow: int = 0
sys.stdout.write('[{}] 0%'.format(progressbar_count * '=')) self.__PbarFullChar: int = 50
self.__PercentPerFile: float = 1 / self.__FileCount
self.__CurFileName: str = None
self.__Render()
def StepFile(self, newfile: str, content_len: int):
if self.__CurFileName is not None:
# not first call, INC FileNow
# if first call, do not INC it
self.__FileNow += 1
# apply others
self.__CurFileName = newfile
self.__ContentNow = 0
self.__ContentCount = content_len
self.__Render()
def StepContent(self):
self.__ContentNow += 1
self.__Render()
def Finish(self):
sys.stdout.write('\n')
sys.stdout.flush() sys.stdout.flush()
def stepProgressbar(): def __Render(self):
global value_Now, value_All percentage_content: float = 0 if self.__ContentCount == 0 else (self.__ContentNow / self.__ContentCount)
value_Now += 1 percentage_full: float = (percentage_content + self.__FileNow) * self.__PercentPerFile
if (value_Now > value_All):
value_Now = value_All
percentage = int(value_Now / value_All * 100) percentage_bar = int(percentage_full * self.__PbarFullChar)
percentage_bar = int(value_Now / value_All * progressbar_count)
sys.stdout.write('\r[{}{}] {}%'.format(percentage_bar * '#',(progressbar_count - percentage_bar) * '=', percentage))
sys.stdout.flush()
def finProgressbar(): sys.stdout.write('\r[{}{}] {:.2f}% - {}'.format(
sys.stdout.write('\r[{}] 100%\n'.format(progressbar_count * '#')) percentage_bar * '#',
(self.__PbarFullChar - percentage_bar) * '=',
percentage_full * 100,
self.__CurFileName
))
sys.stdout.flush() sys.stdout.flush()

View File

@ -1,53 +1,51 @@
import CustomConfig import CustomConfig, DecoratorCore, Progressbar
import DecoratorCore import os, sys, getopt, logging, time
import os
import sys
import getopt
import logging
# print banner
print('Super Script Decorator')
print('Homepage: https://github.com/yyc12345/SuperScriptMaterializer')
print('Report bug: https://github.com/yyc12345/SuperScriptMaterializer/issues')
print('')
# try get args
try: try:
opts, args = getopt.getopt(sys.argv[1:], "hi:o:e:c:fd") opts, args = getopt.getopt(sys.argv[1:], "hi:o:e:c:fd")
except getopt.GetoptError: except getopt.GetoptError:
print('Wrong arguments!') print('Wrong arguments!')
print('python SuperScriptViewer.py -i <import.txt> -o <decorated.db> -c <codec_name> -d') print('python SuperScriptViewer.py -i <import.txt> -o <decorated.db> -c <codec_name> -d')
sys.exit(1) sys.exit(1)
# analyze args
cfg: CustomConfig.CustomConfig = CustomConfig.CustomConfig()
for opt, arg in opts: for opt, arg in opts:
if opt == '-h': if opt == '-h':
print('python SuperScriptViewer.py -i <import.txt> -o <decorated.db> -c <codec_name> -d') print('python SuperScriptViewer.py -i <import.txt> -o <decorated.db> -c <codec_name> -d')
sys.exit(0) sys.exit(0)
elif opt == '-i': elif opt == '-i':
CustomConfig.export_db = arg cfg.m_ImportTxt = arg
elif opt == '-o': elif opt == '-o':
CustomConfig.decorated_db = arg cfg.m_DecoratedDb = arg
elif opt == '-c': elif opt == '-c':
CustomConfig.database_encoding = arg cfg.m_DatabaseEncoding = arg
elif opt == '-d': elif opt == '-d':
CustomConfig.debug_mode = True cfg.m_DebugMode = True
print('Super Script Decorator') # regulate data
print('Homepage: https://github.com/yyc12345/SuperScriptMaterializer') if not cfg.Regulate():
print('Report bug: https://github.com/yyc12345/SuperScriptMaterializer/issues') # failed. exit program
print('')
# process input and output
if not os.path.isfile(CustomConfig.export_db):
print('No import.txt. Fail to generate. Exit app.')
sys.exit(1) sys.exit(1)
# real db generator func # if in debug mode, run directly
def dc_wrapper(): # otherwise, run with a try wrapper.
pass if cfg.m_DebugMode:
DecoratorCore.run(cfg)
# generate db
if CustomConfig.debug_mode:
DecoratorCore.run()
else: else:
try: try:
DecoratorCore.run() DecoratorCore.run(cfg)
except Exception, ex: except Exception as ex:
print("!!! An error occurs. Please report follwoing error output and reproduce file to developer. !!!") print("!!! An error occurs. Please report follwoing error output and reproduce file to developer. !!!")
logging.exception(ex) logging.exception(ex)
sys.exit(1) sys.exit(1)
print('Decorated database generating done.') print('Decorated database generation done.')

View File

@ -1,50 +0,0 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>6d751bf5-87d6-4123-94b3-34721938cf04</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>SuperScriptDecorator.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>SuperScriptDecorator</Name>
<RootNamespace>SuperScriptDecorator</RootNamespace>
<LaunchProvider>Standard Python launcher</LaunchProvider>
<CommandLineArguments>-f -d</CommandLineArguments>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="CustomConfig.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="DecoratorConstValue.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="DecoratorCore.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="Progressbar.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="SuperScriptDecorator.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
</Project>

View File

@ -3,40 +3,22 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.29418.71 VisualStudioVersion = 16.0.29418.71
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "SuperScriptDecorator", "SuperScriptDecorator\SuperScriptDecorator.pyproj", "{6D751BF5-87D6-4123-94B3-34721938CF04}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SuperScriptMaterializer", "SuperScriptMaterializer\SuperScriptMaterializer.vcxproj", "{4D941003-020F-47FD-9FA2-FFC989E306B8}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SuperScriptMaterializer", "SuperScriptMaterializer\SuperScriptMaterializer.vcxproj", "{4D941003-020F-47FD-9FA2-FFC989E306B8}"
EndProject EndProject
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "SuperScriptViewer", "SuperScriptViewer\SuperScriptViewer.pyproj", "{0E4B5021-27EA-4F79-B87D-E123AFB3D788}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GPVirtoolsStatic", "GPVirtoolsStatic\GPVirtoolsStatic.vcxproj", "{38703AB6-BC5D-4062-BC5B-1BF195333B16}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GPVirtoolsStatic", "GPVirtoolsStatic\GPVirtoolsStatic.vcxproj", "{38703AB6-BC5D-4062-BC5B-1BF195333B16}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86 Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86 Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6D751BF5-87D6-4123-94B3-34721938CF04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D751BF5-87D6-4123-94B3-34721938CF04}.Debug|x86.ActiveCfg = Debug|Any CPU
{6D751BF5-87D6-4123-94B3-34721938CF04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D751BF5-87D6-4123-94B3-34721938CF04}.Release|x86.ActiveCfg = Release|Any CPU
{4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|Any CPU.ActiveCfg = Debug|Win32
{4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|x86.ActiveCfg = Debug|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|x86.ActiveCfg = Debug|Win32
{4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|x86.Build.0 = Debug|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Debug|x86.Build.0 = Debug|Win32
{4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|Any CPU.ActiveCfg = Release|Win32
{4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|x86.ActiveCfg = Release|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|x86.ActiveCfg = Release|Win32
{4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|x86.Build.0 = Release|Win32 {4D941003-020F-47FD-9FA2-FFC989E306B8}.Release|x86.Build.0 = Release|Win32
{0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Debug|x86.ActiveCfg = Debug|Any CPU
{0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E4B5021-27EA-4F79-B87D-E123AFB3D788}.Release|x86.ActiveCfg = Release|Any CPU
{38703AB6-BC5D-4062-BC5B-1BF195333B16}.Debug|Any CPU.ActiveCfg = Debug|Win32
{38703AB6-BC5D-4062-BC5B-1BF195333B16}.Debug|x86.ActiveCfg = Debug|Win32 {38703AB6-BC5D-4062-BC5B-1BF195333B16}.Debug|x86.ActiveCfg = Debug|Win32
{38703AB6-BC5D-4062-BC5B-1BF195333B16}.Debug|x86.Build.0 = Debug|Win32 {38703AB6-BC5D-4062-BC5B-1BF195333B16}.Debug|x86.Build.0 = Debug|Win32
{38703AB6-BC5D-4062-BC5B-1BF195333B16}.Release|Any CPU.ActiveCfg = Release|Win32
{38703AB6-BC5D-4062-BC5B-1BF195333B16}.Release|x86.ActiveCfg = Release|Win32 {38703AB6-BC5D-4062-BC5B-1BF195333B16}.Release|x86.ActiveCfg = Release|Win32
{38703AB6-BC5D-4062-BC5B-1BF195333B16}.Release|x86.Build.0 = Release|Win32 {38703AB6-BC5D-4062-BC5B-1BF195333B16}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection

View File

@ -1,38 +0,0 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>0e4b5021-27ea-4f79-b87d-e123afb3d788</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>SuperScriptViewer.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>SuperScriptViewer</Name>
<RootNamespace>SuperScriptViewer</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="CustomConfig.py" />
<Compile Include="ServerCore.py" />
<Compile Include="ServerStruct.py" />
<Compile Include="SuperScriptViewer.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
</Project>

2
example.txt Normal file
View File

@ -0,0 +1,2 @@
Ballance/vt2obj "example.nmo" "export.db" "env.db"
"Ballance/vt2obj mirror" Gameplay.nmo export.db env.db