#include <File.au3>
HotKeySet("{ESC}", "Terminate")
AutoItSetOption("MustDeclareVars", 1)
Local $i
Local $sSourceFile, $sDestFile, $sDestPath, $sExePath, $Dir, $sReadFileModel, $sReadFileSkelet, $sWriteFile, $sReadFileModel2, $sOutputFile, $sSuf
Local $sDrive, $sFolder, $sFileName, $sExt, $sParams, $sRunWait, $TextFile1, $TextFile2, $sModelFile, $sSkeletonFile
If $CmdLine[0] <> 0 Then
ProgressOn("Converting", "", "0%")
For $i = 1 To $CmdLine[0]
$sSourceFile = $CmdLine[$i]
_PathSplit($sSourceFile, $sDrive, $sFolder, $sFileName, $sExt)
ProgressSet(($i / $CmdLine[0]) * 100, $sFileName & $sExt, String(Round($i / $CmdLine[0] * 100, 1)) & "%")
If FileExists($sSourceFile) Then
$sSuf = '_011'
_FileRename_($sSourceFile, @WorkingDir & '\' & $sFileName & $sSuf & $sExt, 1)
_FileRename_(@WorkingDir & '\' & $sFileName & '_skel.smd', @WorkingDir & '\' & $sFileName & $sSuf & '_skel' & $sExt, 1)
_FileRename_(@WorkingDir & '\' & $sFileName & '-base' & '_skel.smd', @WorkingDir & '\' & $sFileName & '_012' & '_skel' & $sExt, 1)
$sModelFile = @WorkingDir & '\' & $sFileName & $sSuf & $sExt
$sSkeletonFile = @WorkingDir & '\' & $sFileName & $sSuf & '_skel' & $sExt
;~ ConsoleWrite("Model: " & $sModelFile & @CRLF)
;~ ConsoleWrite("Skeleton: " & $sSkeletonFile & @CRLF)
$sOutputFile = @WorkingDir & '\' & $sFileName & '_rigged.smd'
$sReadFileModel = StringRegExp($sModelFile, '(^.*)\\(.*)\.(.*)$', 3)
$sReadFileModel2 = StringRegExpReplace($sModelFile, ".+\\(.+)\_.+", "\1", 1)
$sReadFileSkelet = _FileListToArray($sReadFileModel[0] & '\', $sReadFileModel2 & '_*_skel.' & $sReadFileModel[2], 1)
If Not @error Then
$TextFile1 = StringTrimLeft(FileRead($sModelFile),1)
$TextFile2 = FileRead($sReadFileSkelet[1])
FileWrite($sOutputFile,$TextFile2&$TextFile1)
_FileDeleteEmptyLines($sOutputFile)
Else
MsgBox(16, 'Ошибка', 'Не найден файл для замены')
EndIf
_FileRename_(@WorkingDir & '\' & $sFileName & $sSuf & $sExt, $sSourceFile, 1)
_FileRename_(@WorkingDir & '\' & $sFileName & $sSuf & '_skel' & $sExt, @WorkingDir & '\' & $sFileName & '_skel.smd', 1)
_FileRename_(@WorkingDir & '\' & $sFileName & '_012' & '_skel' & $sExt, @WorkingDir & '\' & $sFileName & '-base' & '_skel.smd', 1)
Else
MsgBox(0, 'Error', "File [" & $sSourceFile & "] not found")
EndIf
Next
ProgressSet(100, "Converting complete", "100%")
Sleep(1000)
ProgressOff()
Else
MsgBox(0, "Usage", "Drop file(s) on " & @ScriptName)
ConsoleWrite("Usage: " & @ScriptName & " <file>" & @CRLF)
EndIf
Func _FileDeleteEmptyLines($sFile)
Local $sFileContent = StringRegExpReplace(FileRead($sFile), "(\r?\n){1,}", "\1")
Local $hFOpen = FileOpen($sFile, 2 + FileGetEncoding($sFile))
FileWrite($hFOpen, StringStripWS($sFileContent, 3))
FileClose($hFOpen)
EndFunc
; ## FUNCTION ##=========================================================================
; Name ..............: _FileRename_
; Description .......: Rename a File
; Syntax ............: _FileRename_($s_Source, $s_Destination, $i_Flag = 0)
; Parameters ........: $s_Source Source File
; $s_Destination Destination File
; $i_Flag Flag 0 = (default) do not overwrite existing files
; 1 = overwrite existing files
; 8 = Create destination directory structure if it doesn't exist
; Return values .....: Success: Returns 1
; Failure: Returns 0
; Author ............: 'charvi' <charvista at gmail dot com>
; Creation Date .....: 2009-01-05
; Version ...........: 0.0.0.1
; Version Date ......: 2009-01-05
; Remarks ...........: If the source and destination paths are on different volumes a copy and delete operation is performed rather than a move.
; The destination directory must already exist, except using with flag value '8'.
; For instance the combined flag '9' (1 + 8) overwrites the target file and prechecks for the destination directory structure and if it doesn't exist creates it automatically.
; Some file attributes can make the overwriting impossible.
;========================================================================================
Func _FileRename_($s_Source, $s_Destination, $i_Flag = 0)
Local $i
$i = FileMove($s_Source, $s_Destination, $i_Flag)
Return $i
EndFunc
Func Terminate()
Exit
EndFunc ;==>Terminate
Exit (0)