-
Notifications
You must be signed in to change notification settings - Fork 20
/
conf2cf.cmd
221 lines (189 loc) · 8.22 KB
/
conf2cf.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
@rem ----------------------------------------------------------
@rem This Source Code Form is subject to the terms of the
@rem Mozilla Public License, v.2.0. If a copy of the MPL
@rem was not distributed with this file, You can obtain one
@rem at http://mozilla.org/MPL/2.0/.
@rem ----------------------------------------------------------
@rem Codebase: https://github.com/ArKuznetsov/1CFilesConverter/
@rem ----------------------------------------------------------
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
IF not defined V8_ENCODING set V8_ENCODING=65001
chcp %V8_ENCODING% > nul
set CONVERT_VERSION=UNKNOWN
IF exist "%~dp0..\VERSION" FOR /F "usebackq tokens=* delims=" %%i IN ("%~dp0..\VERSION") DO set CONVERT_VERSION=%%i
echo 1C files converter v.%CONVERT_VERSION%
echo ======
echo [INFO] Convert 1C configuration to 1C configuration file ^(*.cf^)
set ERROR_CODE=0
IF exist "%cd%\.env" IF "%V8_SKIP_ENV%" neq "1" (
FOR /F "usebackq tokens=*" %%a in ("%cd%\.env") DO (
FOR /F "tokens=1* delims==" %%b IN ("%%a") DO (
IF not defined %%b set "%%b=%%c"
)
)
)
IF not defined V8_VERSION set V8_VERSION=8.3.23.2040
IF not defined V8_TEMP set V8_TEMP=%TEMP%\1c
echo [INFO] Using 1C:Enterprise, version %V8_VERSION%
echo [INFO] Using temporary folder "%V8_TEMP%"
IF not "%V8_CONVERT_TOOL%" equ "designer" IF not "%V8_CONVERT_TOOL%" equ "ibcmd" set V8_CONVERT_TOOL=designer
IF not defined V8_TOOL set V8_TOOL="%PROGRAMW6432%\1cv8\%V8_VERSION%\bin\1cv8.exe"
IF "%V8_CONVERT_TOOL%" equ "designer" IF not exist %V8_TOOL% (
echo Could not find 1C:Designer with path %V8_TOOL%
set ERROR_CODE=1
goto finally
)
IF not defined IBCMD_TOOL set IBCMD_TOOL="%PROGRAMW6432%\1cv8\%V8_VERSION%\bin\ibcmd.exe"
IF "%V8_CONVERT_TOOL%" equ "ibcmd" IF not exist %IBCMD_TOOL% (
echo Could not find ibcmd tool with path %IBCMD_TOOL%
set ERROR_CODE=1
goto finally
)
echo [INFO] Start conversion using "%V8_CONVERT_TOOL%"
set LOCAL_TEMP=%V8_TEMP%\%~n0
if not defined IBCMD_DATA set IBCMD_DATA=%V8_TEMP%\ibcmd_data
set IB_PATH=%LOCAL_TEMP%\tmp_db
set XML_PATH=%LOCAL_TEMP%\tmp_xml
set WS_PATH=%LOCAL_TEMP%\edt_ws
set ARG=%1
IF defined ARG set ARG=%ARG:"=%
IF "%ARG%" neq "" set V8_SRC_PATH=%ARG%
set ARG=%2
IF defined ARG set ARG=%ARG:"=%
IF "%ARG%" neq "" set V8_DST_PATH=%ARG%
set V8_DST_FOLDER=%~dp2
set V8_DST_FOLDER=%V8_DST_FOLDER:~0,-1%
IF not defined V8_SRC_PATH (
echo [ERROR] Missed parameter 1 - "path to 1C configuration source (infobase, 1C:Designer XML files or 1C:EDT project)"
set ERROR_CODE=1
)
IF not defined V8_DST_PATH (
echo [ERROR] Missed parameter 2 - "path to 1C configuration file (*.cf)"
set ERROR_CODE=1
)
IF %ERROR_CODE% neq 0 (
echo ======
echo [ERROR] Input parameters error. Expected:
echo %%1 - path to 1C configuration source ^(infobase, 1C:Designer XML files or 1C:EDT project^)
echo %%2 - path to 1C configuration file ^(*.cf^)
echo.
goto finally
)
echo [INFO] Clear temporary files...
IF exist "%LOCAL_TEMP%" rd /S /Q "%LOCAL_TEMP%"
md "%LOCAL_TEMP%"
IF not exist "%V8_DST_FOLDER%" md "%V8_DST_FOLDER%"
echo [INFO] Checking configuration source type...
IF exist "%V8_SRC_PATH%\DT-INF\" (
echo [INFO] Source type: 1C:EDT project
set V8_IB_CONNECTION=File="!IB_PATH!";
goto export_edt
)
IF exist "%V8_SRC_PATH%\Configuration.xml" (
echo [INFO] Source type: 1C:Designer XML files
set XML_PATH=%V8_SRC_PATH%
set V8_IB_CONNECTION=File="!IB_PATH!";
goto export_xml
)
IF /i "%V8_SRC_PATH:~0,2%" equ "/F" (
set IB_PATH=%V8_SRC_PATH:~2%
echo [INFO] Source type: File infobase ^(!IB_PATH!^)
set V8_IB_CONNECTION=File="!IB_PATH!";
goto export_ib
)
IF /i "%V8_SRC_PATH:~0,2%" equ "/S" (
set IB_PATH=%V8_SRC_PATH:~2%
FOR /F "tokens=1,2 delims=\" %%a IN ("!IB_PATH!") DO (
set V8_IB_SERVER=%%a
set V8_IB_NAME=%%b
)
echo [INFO] Source type: Server infobase ^(!V8_IB_SERVER!\!V8_IB_NAME!^)
set IB_PATH=!V8_IB_SERVER!\!V8_IB_NAME!
set V8_IB_CONNECTION=Srvr="!V8_IB_SERVER!";Ref="!V8_IB_NAME!";
IF not defined V8_DB_SRV_DBMS set V8_DB_SRV_DBMS=MSSQLServer
goto export_ib
)
IF exist "%V8_SRC_PATH%\1cv8.1cd" (
echo [INFO] Source type: File infobase ^(!V8_SRC_PATH!^)
set IB_PATH=%V8_SRC_PATH%
set V8_IB_CONNECTION=File="!V8_SRC_PATH!";
goto export_ib
)
echo [ERROR] Error cheking type of configuration "%V8_SRC_PATH%"!
echo Infobase, 1C:Designer XML files or 1C:EDT project expected.
set ERROR_CODE=1
goto finally
:export_edt
IF not exist "%XML_PATH%" md "%XML_PATH%"
md "%WS_PATH%"
echo [INFO] Export "%V8_SRC_PATH%" to 1C:Designer XML format "%XML_PATH%"...
IF not defined RING_TOOL (
FOR /F "usebackq tokens=1 delims=" %%i IN (`where ring`) DO (
set RING_TOOL="%%i"
)
)
IF not defined EDTCLI_TOOL (
IF defined V8_EDT_VERSION (
IF %V8_EDT_VERSION:~0,4% lss 2024 goto checktool
set EDT_MASK="%PROGRAMW6432%\1C\1CE\components\1c-edt-%V8_EDT_VERSION%*"
) ELSE (
set EDT_MASK="%PROGRAMW6432%\1C\1CE\components\1c-edt-*"
)
FOR /F "tokens=*" %%d IN ('"dir /B /S !EDT_MASK! | findstr /r /i ".*1c-edt-[0-9]*\.[0-9]*\.[0-9].*""') DO (
IF exist "%%d\1cedtcli.exe" set EDTCLI_TOOL="%%d\1cedtcli.exe"
)
)
:checktool
IF not defined RING_TOOL IF not defined EDTCLI_TOOL (
echo [ERROR] Can't find "ring" or "edtcli" tool. Add path to "ring.bat" to "PATH" environment variable, or set "RING_TOOL" variable with full specified path to "ring.bat", or set "EDTCLI_TOOL" variable with full specified path to "1cedtcli.exe".
set ERROR_CODE=1
goto finally
)
IF defined EDTCLI_TOOL (
echo [INFO] Start conversion using "edt cli"
call %EDTCLI_TOOL% -data "%WS_PATH%" -command export --project "%V8_SRC_PATH%" --configuration-files "%XML_PATH%"
) ELSE (
echo [INFO] Start conversion using "ring"
call %RING_TOOL% edt@%V8_EDT_VERSION% workspace export --project "%V8_SRC_PATH%" --configuration-files "%XML_PATH%" --workspace-location "%WS_PATH%"
)
IF not ERRORLEVEL 0 (
set ERROR_CODE=%ERRORLEVEL%
goto finally
)
:export_xml
IF not exist "%IB_PATH%" md "%IB_PATH%"
IF "%V8_CONVERT_TOOL%" equ "designer" (
set V8_DESIGNER_LOG=%LOCAL_TEMP%\v8_designer_output.log
echo [INFO] Creating infobase "%IB_PATH%"...
%V8_TOOL% CREATEINFOBASE %V8_IB_CONNECTION% /DisableStartupDialogs /Out "!V8_DESIGNER_LOG!"
FOR /F "tokens=* delims=" %%i IN (!V8_DESIGNER_LOG!) DO IF "%%i" neq "" echo [WARN] %%i
echo [INFO] Loading infobase "%IB_PATH%" configuration from XML-files "%XML_PATH%"...
%V8_TOOL% DESIGNER /IBConnectionString %V8_IB_CONNECTION% /DisableStartupDialogs /Out "!V8_DESIGNER_LOG!" /LoadConfigFromFiles "%XML_PATH%"
FOR /F "tokens=* delims=" %%i IN (!V8_DESIGNER_LOG!) DO IF "%%i" neq "" echo [WARN] %%i
) ELSE (
echo [INFO] Creating infobase "%IB_PATH%" with configuration from XML-files "%XML_PATH%"...
%IBCMD_TOOL% infobase create --data="%IBCMD_DATA%" --db-path="%IB_PATH%" --create-database --import="%XML_PATH%"
)
IF not ERRORLEVEL 0 (
set ERROR_CODE=%ERRORLEVEL%
goto finally
)
:export_ib
echo [INFO] Export infobase "%IB_PATH%" configuration to "%V8_DST_PATH%"...
IF "%V8_CONVERT_TOOL%" equ "designer" (
set V8_DESIGNER_LOG=%LOCAL_TEMP%\v8_designer_output.log
%V8_TOOL% DESIGNER /IBConnectionString %V8_IB_CONNECTION% /N"%V8_IB_USER%" /P"%V8_IB_PWD%" /DisableStartupDialogs /Out "!V8_DESIGNER_LOG!" /DumpCfg "%V8_DST_PATH%"
FOR /F "tokens=* delims=" %%i IN (!V8_DESIGNER_LOG!) DO IF "%%i" neq "" echo [WARN] %%i
) ELSE (
IF defined V8_IB_SERVER (
%IBCMD_TOOL% infobase config save --data="%IBCMD_DATA%" --dbms=%V8_DB_SRV_DBMS% --db-server=%V8_IB_SERVER% --db-name="%V8_IB_NAME%" --db-user="%V8_DB_SRV_USR%" --db-pwd="%V8_DB_SRV_PWD%" --user="%V8_IB_USER%" --password="%V8_IB_PWD%" "%V8_DST_PATH%"
) ELSE (
%IBCMD_TOOL% infobase config save --data="%IBCMD_DATA%" --db-path="%IB_PATH%" --user="%V8_IB_USER%" --password="%V8_IB_PWD%" "%V8_DST_PATH%"
)
)
set ERROR_CODE=%ERRORLEVEL%
:finally
echo [INFO] Clear temporary files...
IF exist "%LOCAL_TEMP%" rd /S /Q "%LOCAL_TEMP%"
exit /b %ERROR_CODE%