@echo off
chcp 1251 >nul
@echo       

REM :
REM     www.oemhelp.fatal.ru   
REM   OEM .       .
REm  OEM XP RUS SP1, SP2  GGK (     
REm   ,       ).
REm     Brand .
REM 
REM ,            
REM    PRO  HOME (   , 
REM ( %DistType%)
REM 
REM      .
REM 
REM          
REM    (__Patch.cmd   ):
REM 
REM OEMBIOSPath --      brand OEM BIOS XP.   ,
REM                     Archive  .
REM 
REM DistType -- ,    , PRO  HOME (  ).
REM 
REM ArcPath  --     ,  7z.exe 
REM 
REM ArchSwitch --    ,  7z.exe   e -y 
REM 
REM UDBFileName --  UDB     
REM 
REM UDB_Path --   UDB 
REM 
REM 

SETLOCAL

if [%RDir%]==[] set RDir=%CD%\%~1
if [%DistType%]==[] Set DistType=pro

set BrandDir=%Distr%\BRAND


if [%OEMBIOSPath%]==[] set OEMBIOSPath=%RDir%\Archive
IF [%ArcPath%]==[] SET ArcPath=C:\ARH\7z\7z.exe 

IF ['']==['%ArchSwitch%'] SET ArchSwitch=e -y
set ArchFileMask=*%DistType%*.*


pushD %OEMBIOSPath%

eCHO Unpack brand oem-bios files:
Echo.

set Fl=%~dp0Fl.txt


call :MAkeFileList
   
if [%UDBFileName%]==[] set UDBFileName=BRAND_%DistType%.UDB

if [%UDB_Path%]==[] (
 set UDB_Path=%BrandDir%
  Echo    UDB_Path.     -- '!UDB_Path!'
  Echo. 
)
MD %UDB_Path% >nul

for /D %%K in (*) do (

 if not exist %BrandDir%\%%K md %BrandDir%\%%K
 Set errorlevel=
 %ArcPath% %ArchSwitch% -o%BrandDir%\%%K %OEMBIOSPath%\%%K\%ArchFileMask% @%FL% 2>NUL 1>nul
 if ERRORLEVEL 2 (rd %BrandDir%\%%K 2>nul) else (echo %%K
   Rem   PROF  HOME , "" ,   .
   For /F %%A in ('dir %BrandDir%\%%K\*.??_ /b') do (
     Expand.exe -r %BrandDir%\%%K\%%A > nul
     Del /f %BrandDir%\%%K\%%A
   )
   REM     UDB  ().
   call :MakeUDB %BrandDir%\%%K %%K
 )
 
 
)
del %FL%
popd
REM  FileWatcher, finishMerger  %BrandDir%

Copy %RDir%\FilesCD\*.exe %BrandDir% >nul
Copy %RDir%\FilesCD\*.ini %BrandDir% >nul

REM 
Copy %RDir%\COPY_OEM.CMD %UDB_Path% >nul

Echo.
ENDLOCAL
chcp 866 > nul
Goto :EOF

:MAkeFileList
@echo off
SET fl=%FL%
Echo dpcdll.dl_ >%FL%
Echo dpcdll.dll >>%FL%
Echo eula.txt   >>%FL%
Echo oembios.bi_>>%FL%
Echo oembios.bin>>%FL%
Echo oembios.ca_>>%FL%
Echo oembios.cat>>%FL%
Echo oembios.da_>>%FL%
Echo oembios.dat>>%FL%
Echo oembios.si_>>%FL%
Echo oembios.sig>>%FL%
Echo pidgen.dll >>%FL%
Echo setupp.ini >>%FL%
Echo winnt.sif  >>%FL%

Goto :Eof


:MakeUDB
setlocal
REM  UDB  ( )
Echo off

set FN=%UDB_Path%\%UDBFileName%

Set FileToRead=%1\Winnt.sif

for /f "tokens=*" %%i in ('%RDir%\setini.exe read %FileToRead% UserData ProductKey') do set PK=%%i 

if [%Value%]==[] for /f "tokens=*" %%i in ('%RDir%\setini.exe read %FileToRead% UserData ProductID') do set PK=%%i 

if [%useT40Editor%]==[] set useT40Editor=1
if [%useT40Editor%]==[1] (set SK=UserData, T40Editor) else (Set SK=UserData)



%RDir%\Setini write %FN% UniqueIds %2_%DistType% "%SK%"
%RDir%\setini write %FN% "%2_%DistType%:UserData" ProductKey "%PK%"
if [%useT40Editor%]==[1] (
  %RDir%\setini write %FN% %2_%DistType%:T40Editor RunOnExit "%%SourceRoot%%\UDB\COPY_OEM.CMD %2"

  %RDir%\setini write %FN% %2_%DistType%:T40Editor Description01 " Windows XP SP2 RUS    %2."
  %RDir%\setini write %FN% %2_%DistType%:T40Editor Description02 "  ,   %2.     ."
)
echo off
endlocal
goto :Eof

///////////////
