[Android Themes] AChep:
Source code of acPatcher 5.0 BETA

Language: Pascal

program achep_patcher;
var h3,b5:array [1..5000] of integer;
f2,lang,datefile,resources,log:text;
m,m1,w,w1,numb,text,l,h1,h2,h4:array [1..5000] of string;
version,minversion:real;
apps,frameworks,number,p1,p2,i,i1,c,x,k,i3,n,b1,b2,b3,b4,b,textn,textm:integer;
date,name,author,rom,recovery,cache,cache2,adb,update,res,c1,hiera,cache3,cache4:string;

qtext:array[1..1000] of string;
vername:string;
ex:boolean;
qtextn,acpatch:integer;
begin

version:=5.0;

///Лог
assign(log,'log.txt');
rewrite(log);
writeln(log,'AC: Создан лог событий');

///мультиязычность при старте
if FileExists('tools\lang-installed')<>true then begin
exec('lang-manager.exe');
writeln(log,'AC: Запущен языковой менеджер');
write('Press Enter to continue!');
write('');
write('');
readln();
end;

///Берем текст
l[1]:='Warning: acpatch\resources.txt was not found!';
l[2]:='Warning: acpatch\resources.txt was made not correct!';
l[3]:='Warning: Information about acpatch version not found!';
l[4]:='Wellcome to';
l[5]:='Continue';
l[6]:='exit';
l[7]:='Make your decision:';
l[8]:='This acpatch was created for ROM:';
l[9]:='By';
l[10]:='Note:';
l[11]:='Do you ready?';
l[12]:='Sorry, but you are using an old version of acPatcher';
l[13]:='Please update acPatcher from this link:';
l[14]:='Pull files from your the device';
l[15]:='Pull files from acPatcher\res\';
l[16]:='Create update.zip for xRecovery';
l[17]:='Create update.zip for CWM Recovery';
l[18]:='This acpatch include';
l[19]:='different versions';
l[20]:='Hierachy system:';
l[21]:='Warning: Time has expired!';
l[22]:='Force close! Error 1: resources.txt';
l[23]:='Force close! Error 2: resources.txt';
l[24]:='Force close! Error 3: resources.txt';
l[25]:='not found!';
l[26]:='Do you want miss this file?';

///мульти-язычность
if FileExists('tools\lang-installed')=true then begin
assign(lang,'tools\lang-installed');
reset(lang);
ex:=false;
while not Eof(lang) do begin
///удаление всех пробелов за и перед текстом
readln(lang,cache);
while cache='' do begin
readln(lang,cache);
if Eof(lang)=true then begin
ex:=true;
break;
end;
end;
if ex=true then break;

while cache[1]=' ' do cache:=copy(cache,2,length(cache));
while cache[length(cache)]=' ' do cache:=copy(cache,1,length(cache)-1);

///разрезаем текст на две части
p1:=pos('="',cache);
p2:=length(cache);
p2:=p2-p1-2;
cache2:=copy(cache,1,p1-1);
cache:=copy(cache,p1+2,p2);

///Замена текста
if (cache2='warning1') then l[1]:=cache;
if (cache2='warning2') then l[2]:=cache;
if (cache2='warning3') then l[3]:=cache;
if (cache2='wellcome') then l[4]:=cache;
if (cache2='continue') then l[5]:=cache;
if (cache2='exit') then l[6]:=cache;
if (cache2='decision') then l[7]:=cache;
if (cache2='rom') then l[8]:=cache;
if (cache2='byauthor') then l[9]:=cache;
if (cache2='note') then l[10]:=cache;
if (cache2='ready') then l[11]:=cache;
if (cache2='sorry') then l[12]:=cache;
if (cache2='update') then l[13]:=cache;
if (cache2='pullfromdevice') then l[14]:=cache;
if (cache2='pullfromfs') then l[15]:=cache;
if (cache2='xrec') then l[16]:=cache;
if (cache2='cwmrec') then l[17]:=cache;
if (cache2='include1') then l[18]:=cache;
if (cache2='include2') then l[19]:=cache;
if (cache2='hiera') then l[20]:=cache;
if (cache2='warning4') then l[21]:=cache;
end;
close(lang);
writeln(log,'AC: Изменены реплики в соответствии с установленным языком');
end;

///проверка на файлы ацпатча
if FileExists('acpatch\resources.txt')<>true then begin
writeln(l[1]);
writeln(log,' - - - - - - - - - -');
writeln(log,'ERROR: Файл resources.txt не найден!');
writeln(log,'SOLVE: Сообщите автору патча об этом');
close(log);
readln();
exit;
end;

/// взятие данных из RESOURCES.TXT
writeln(log,'AC: Взятие данных из resources.txt...');
assign(resources,'acpatch\resources.txt');
reset(resources);
ex:=false;
while not Eof(resources) do begin

readln(resources,cache);
while cache='' do begin
readln(resources,cache);
if Eof(resources)=true then begin
ex:=true;
break;
end;
end;
if ex=true then break;
while cache[1]=' ' do cache:=copy(cache,2,length(cache));
while cache[length(cache)]=' ' do cache:=copy(cache,1,length(cache)-1);

p1:=pos('="',cache);
p2:=length(cache);
p2:=p2-p1-2;
cache3:=cache;
cache2:=copy(cache,1,p1-1);
cache:=copy(cache,p1+2,p2);

if (cache2='minVersion') then val(cache,minversion,i);
if (cache2='dateProject') then date:=cache;
if (cache2='nameProject') then name:=cache;
if (cache2='authorProject') then author:=cache;
if (cache2='versionProject') then vername:=cache;
if (cache2='romProject') then rom:=cache;

///Обработка списка дополнительного текста
if (cache3='TEXT BEGIN:') then begin
i:=0;
while cache<>'/END' do begin
readln(resources,cache);
while cache='' do begin
readln(resources,cache);
if Eof(resources)=true then begin
writeln(l[22]);
writeln(log,'ERROR: Ошибка №1 в resources.txt');
writeln(log,'SOLVE: Сообщите автору патча об этом');
close(log);
readln();
exit;
end;
end;
if cache='/END' then break;
while cache[1]=' ' do cache:=copy(cache,2,length(cache));
while cache[length(cache)]=' ' do cache:=copy(cache,1,length(cache)-1);
i:=i+1;
qtext[i]:=cache;
end;
qtextn:=i;
end;

///Обработка списка приложений
if (cache3='SYSTEM APPS BEGIN:') then begin
i:=0;
while cache<>'/END' do begin
readln(resources,cache);
while cache='' do begin
readln(resources,cache);
if Eof(resources)=true then begin
writeln(l[23]);
writeln(log,'ERROR: Ошибка №2 в resources.txt');
writeln(log,'SOLVE: Сообщите автору патча об этом');
close(log);
readln();
exit;
end;
end;
if cache='/END' then break;
while cache[1]=' ' do cache:=copy(cache,2,length(cache));
while cache[length(cache)]=' ' do cache:=copy(cache,1,length(cache)-1);
i:=i+1;
m[i]:=cache;

w[i]:=copy(cache,1,pos('.apk',cache));
end;
apps:=i;
end;

///обработка списка приложений
if (cache='FRAMEWORKS BEGIN:') then begin
i:=0;
while cache<>'/END' do begin
readln(resources,cache);
while cache='' do begin
readln(resources,cache);
if Eof(resources)=true then begin
writeln(l[23]);
writeln(log,'ERROR: Ошибка №3 в resources.txt');
writeln(log,'SOLVE: Сообщите автору патча об этом');
close(log);
readln();
exit;
end;
end;
if cache='/END' then break;
while cache[1]=' ' do cache:=copy(cache,2,length(cache));
while cache[length(cache)]=' ' do cache:=copy(cache,1,length(cache)-1);

///проверка на файлы ацпатча
if FileExists('res\app\'cache)<>true then begin
writeln(log,' - - - - - - - - - -');
writeln(log,'ERROR: Файл res\app\',cache,' не найден!');
writeln(log,'SOLVE: Скопируйте его туда из Вашей системы');
close(log);
writeln('Вы хотите пропустить установку файла');
readln();
exit;
end;

i:=i+1;
m1[i]:=cache;
w1[i]:=copy(cache,1,pos('.apk',cache));
end;
frameworks:=i;
end;
end;
close(resources);

writeln(log,'AC: Обработка resources.txt выполнена');

///Дополнительные условия
if minversion>version then begin
writeln(l[12]);
writeln(' ',l[13]);
writeln(' http://xdaforums.com/showthread.php?t=1335222');
writeln(log,' - - - - - - - - - -');
writeln(log,'ERROR: Устаревшая версия acPatcher"а - невозможно продолжить работу');
writeln(log,'SOLVE: Обновите патчер по этой ссылке:');
writeln(log,' http://xdaforums.com/showthread.php?t=1335222');
close(log);
readln();
exit;
end;
if name='' then begin
writeln(log,' - - - - - - - - - -');
writeln(log,'WARNING: Информация о имени проэкта не найдена');
name:='*unknown*';
writeln(log,'AC: Имя проэкта: *unknown*');
vername:='';
writeln(log,'AC: Информация о версии проэкта не будет использоваться');
end else begin
if vername='' then begin
writeln(log,' - - - - - - - - - -');
writeln(log,'WARNING: Информация о версии проэкта не найдена');
end;
end;
if author='' then begin
writeln(log,' - - - - - - - - - -');
writeln(log,'WARNING: Информация о авторе проэкта не найдена');
author:='*unknown author*';
writeln(log,'AC: Автор проэкта: *unknown author*');
end;
if date='' then begin
writeln(log,' - - - - - - - - - -');
writeln(log,'WARNING: Дата создания проэкта не найдена');
end;
if rom='' then begin
writeln(log,' - - - - - - - - - -');
writeln(log,'WARNING: Не найдена информация о том, для какой прошивки был сделан этот патч');
rom:='*unknown ROM*';
writeln(log,'AC: Прошивка: *unknown ROM*');
end;

close(log);
readln();

writeln('AChep');
writeln(l[4],' acPatcher v',version,'!');
writeln('- - - - - - - - - - - - ');
if minversion=0 then begin
writeln(l[3]);
writeln('');
repeat begin
if k=1 then begin
writeln('');
end;
writeln('1. ',l[5]);
writeln('2. ',l[6]);
write(' ',l[7],' ');
readln(adb);
if (adb<>'1')and(adb<>'2') then k:=1 else k:=0;
end until k=0;
if adb='2' then exit;
writeln('- - - - - - - - - - - - ');
end;
if rom<>'' then begin
writeln(' ',l[8],' ',rom);
writeln('');
end;
if (name<>'') and (author<>'') then begin
writeln(' ',name);
end;
if author<>'' then begin
write(' ',l[9],' ',author);
if date<>'' then begin
writeln(' - ',date);
end else writeln('');
end;

if text[1]<>'' then begin
writeln('');
write(' ',l[10],' ');
if textm=1 then writeln(text[1])
else begin
b1:=length(l[10]);
writeln(text[1]);
cache:='';
for i:=1 to b1+4 do cache:=cache+' ';
for i:=2 to textn do writeln(cache,text[i]);
end;
end;
b1:=0;

writeln('- - - - - - - - - - - - ');
write(l[11]);
readln();
writeln('- - - - - - - - - - - - ');
repeat begin
if k=1 then begin
writeln('');
end;
writeln('1. ',l[14]);
writeln('2. ',l[15]);
if k=1 then writeln('3. ',l[6]);
write(' ',l[7],' ');
readln(adb);
if (adb='3') and (k=1) then exit;
if (adb<>'1')and(adb<>'2') then k:=1 else k:=0;
end until k=0;
writeln('- - - - - - - - - - - - ');

repeat begin
if k=1 then begin
writeln('');
end;
writeln('1. ',l[16]);
writeln('2. ',l[17]);
if k=1 then writeln('3. ',l[6]);
write(' ',l[7],' ');
readln(recovery);
if (recovery='3') and (k=1) then exit;
if (recovery<>'1')and(recovery<>'2') then k:=1 else k:=0;
end until k=0;
if hiera<>'true' then begin
if number>1 then begin
writeln('- - - - - - - - - - - - ');
writeln(l[18],' ',number,' ',l[19]);
writeln('- - - - - - - - - - - - ');
repeat begin
if k=1 then begin
writeln('');
end;
for i:=1 to number do begin
writeln(i,'. ',numb[i]);
end;
write(' ',l[7],' ');
readln(c);
if (c<1)or(c>number) then k:=1 else k:=0;
end until k=0;
str(c,c1);
res:='res'+c1;
end else if (number=1) then res:='res1';
end else begin

writeln('- - - - - - - - - - - - ');

/// взятие данных из RESOURCES.TXT

///патчинг integers
///конец патчинг integers

///ИЕРАРХИЧЕСКАЯ СИСТЕМА
assign(resources,'acpatch\resources.txt');
reset(resources);
i:=0;
n:=1;
while not Eof(resources) do begin
cache:='';
while (cache<>'<hierarchy begin>') do begin
readln(resources,cache);
if length(cache)>1 then
if cache[1]='<' then begin
p2:=pos('>',cache);
cache:=copy(cache,1,p2);
end;
i3:=i3+1;
if (i3=4000) then begin
Writeln(l[21]);
exit;
end;
end;
i3:=0;
b:=0;
while (cache2<>'hierarchy') do begin
cache:='';
while (cache='') do begin
readln(resources,cache);
i3:=i3+1;
if (i3=4000) then begin
Writeln(l[21]);
exit;
end;
end;
while cache[length(cache)]=' ' do cache:=copy(cache,1,length(cache)-1);
p1:=pos('<',cache);
p2:=pos('>',cache);
cache:=copy(cache,p1,p2);
cache3:='';
p1:=pos('="',cache);
if p1=0 then begin
cache2:=copy(cache,pos('<',cache)+2,length(cache)-3);
cache3:='-';
n:=n-1;
for b4:=n+1 to 5000 do
h3[b4]:=0;
end else begin
p2:=length(cache);
p2:=p2-p1-2;
cache2:=copy(cache,2,p1-2);
cache:=copy(cache,p1+2,p2);
if cache[length(cache)]='/' then begin
cache:=copy(cache,1,length(cache)-2);
cache3:='*';
i:=i+1;
b:=b+1;
h3[n]:=h3[n]+1;
end else begin
cache:=copy(cache,1,length(cache)-1);
cache3:='+';
i:=i+1;
h3[n]:=h3[n]+1;
end;
end;
if cache3<>'-' then begin
h1[i]:=cache;
h2[i]:=cache2;
for b2:=1 to n do begin
if b2<>n then begin
str(h3[b2],cache);
h4[i]:=h4[i]+cache+'_';
end else begin
str(h3[b2],cache);
h4[i]:=h4[i]+cache;
end;
end;
if cache3='+' then
n:=n+1;
end;
end;
end;
close(resources);
/// конец (взятие данных из RESOURCES.TXT)
n:=i;
b4:=0;
b3:=0;
b2:=0;
c:=0;
writeln(l[18],' ',b,' ',l[19]);
writeln('- - - - - - - - - - - - ');
writeln(' ',l[20],' ');
res:='';
repeat begin
writeln('');
writeln(' - - - - - - ');
writeln('');
i1:=1;
for i:=1 to n do begin
b1:=0;
val(h4[i],b1,b2);
if b1<>0 then begin
writeln(i1,'. ',h1[i]);
i1:=i1+1;
b5[i1]:=i;
end;
end;
if i1>1 then begin
write(' ',l[7],' ');
readln(c);
b3:=b5[c+1];
end else
res:=h2[b3];
i3:=0;
for i:=1 to n do begin
cache:=h4[i];
if (length(cache))>0 then begin
val(cache[1],b1,b2);
if b1<>c then begin
h4[i]:='';
end else
h4[i]:=copy(h4[i],3,length(h4[i]));
i3:=i3+1;
end;
end;
end until res<>'';

///конец ИЕРАРХИЧЕСКАЯ СИСТЕМА

end;

assign(f2,'patcher.bat');
rewrite(f2);
writeln(f2,'@ECHO OFF');
writeln(f2,'COLOR 0a');
writeln(f2,'echo AChep');
writeln(f2,'echo Wellcome to acPatcher v',version,'!');
writeln(f2,'echo - - - - - - - - - - - - ');
if rom<>'' then begin
writeln(f2,'echo This acpatch was created for ROM: ',rom);
writeln(f2,'echo.');
end;
if (name<>'') and (author<>'') then begin
writeln(f2,'echo ',name);
end;
if author<>'' then begin
write(f2,'echo By ',author);
if date<>'' then begin
writeln(f2,' - ',date);
end else writeln('echo.');
end;
if text[1]<>'' then begin
writeln(f2,'echo.');
write(f2,'echo ',l[10],' ');
if textm=0 then writeln(f2,'echo ',text[1])
else begin
b1:=length(l[10]);
for i:=1 to b1+4 do cache:=cache+' ';
for i:=2 to textn do begin
writeln(f2,'echo ',cache,text[i]);
end;
end;
end;
writeln(f2,'echo - - - - - - - - - - - - ');
writeln(f2,'cd /d "%~dp0tools\"');
if (adb='1') then begin
writeln(f2,':adb');
for i:=1 to apps do begin
writeln(f2,'adb pull /system/app/',m[i],' "%~dp0res\app\',m[i],'"');
end;
for i:=1 to frameworks do begin
writeln(f2,'adb pull /system/framework/',m1[i],' "%~dp0res\framework\',m1[i],'"');
end;
writeln(f2,'if errorlevel 1 (');
writeln(f2,'echo Warning: Device not found. Connect your phone to PC and try again.');
writeln(f2,'pause');
writeln(f2,'goto adb');
writeln(f2,')');
end;
writeln(f2,'');
writeln(f2,'cd /d "%~dp0tools\"');
if recovery='1' then begin
update:='%~dp0update-xrec-'+name;
writeln(f2,'del "',update,'-patch.zip"');
writeln(f2,'del "',update,'-undo.zip"');
writeln(f2,'copy "%~dp0tools\update-xrecovery.zip" "',update,'-patch.zip"');
writeln(f2,'copy "%~dp0tools\update-xrecovery.zip" "',update,'-undo.zip"');
end else begin
update:='%~dp0update-CWMrec-'+name;
writeln(f2,'del "',update,'-patch.zip"');
writeln(f2,'del "',update,'-undo.zip"');
writeln(f2,'copy "%~dp0tools\update-cwmrecovery.zip" "',update,'-patch.zip"');
writeln(f2,'copy "%~dp0tools\update-cwmrecovery.zip" "',update,'-undo.zip"');
end;
writeln(f2,'rmdir "%~dp0tools\update\system" /q /s');
writeln(f2,'xcopy "%~dp0acpatch\',res,'" "%~dp0tools\update\" /y /s');
writeln(f2,'xcopy "%~dp0acpatch\',res,'" "%~dp0tools\update\" /y /s');
for i:=1 to apps do begin
writeln(f2,'rmdir "%~dp0tools\update\system\app\',w[i],'" /q /s');
writeln(f2,'copy "%~dp0res\app\',m[i],'" "%~dp0tools\update\system\app"');
end;
for i:=1 to frameworks do begin
writeln(f2,'rmdir "%~dp0tools\update\system\framework\',w1[i],'" /q /s');
writeln(f2,'copy "%~dp0res\framework\',m1[i],'" "%~dp0tools\update\system\framework"');
end;
writeln(f2,'7za a -tzip "',update,'-undo.zip" "%~dp0tools\update\system"');
for i:=1 to frameworks do begin
writeln(f2,'rmdir "%~dp0res\framework\',w1[i],'" /q /s');
if (w1[i]='framework-res') then writeln(f2,'java -jar "apktool.jar" if "%~dp0res\framework\',m1[i],'"');
writeln(f2,'java -jar "apktool.jar" d "%~dp0res\framework\',m1[i],'" "%~dp0res\framework\',w1[i],'"');
writeln(f2,'if errorlevel 1 goto error',i);
writeln(f2,'goto go',i);
writeln(f2,':error',i);
writeln(f2,'echo.');
writeln(f2,'echo.');
writeln(f2,'echo Warning: Error when decompiling ',m1[i]);
writeln(f2,'pause');
writeln(f2,'goto end');
writeln(f2,':go',i);
writeln(f2,'');
writeln(f2,'xcopy "%~dp0acpatch\',res,'\system\framework\',w1[i],'" "%~dp0res\framework\',w1[i],'" /y /s');
writeln(f2,'');
writeln(f2,'java -jar "apktool.jar" b "%~dp0res\framework\',w1[i],'"');
writeln(f2,'if errorlevel 1 goto errorc',i);
writeln(f2,'goto go',i);
writeln(f2,':errorc',i);
writeln(f2,'echo.');
writeln(f2,'echo.');
writeln(f2,'echo Warning: Error when compiling ',m1[i]);
writeln(f2,'pause');
writeln(f2,'goto end');
writeln(f2,':go',i);
writeln(f2,'');
writeln(f2,'7za a -tzip "%~dp0res\framework\',w1[i],'\dist\',m1[i],'" "%~dp0res\framework\',w1[i],'\build\apk\resources.arsc" -mx=0');
if (w1[i]='framework-res') then writeln(f2,'java -jar "apktool.jar" if "%~dp0res\framework\',w1[i],'\dist\',m1[i],'"');
writeln(f2,'copy "%~dp0res\framework\',w1[i],'\dist\',m1[i],'" "%~dp0tools\update\system\framework\"');
end;
x:=i;
for i:=1 to apps do begin
writeln(f2,'rmdir "%~dp0res\app\',w[i],'" /q /s');
if (w[i]='SystemUI') then writeln(f2,'java -jar "apktool.jar" if "%~dp0res\app\',m[i],'"');
writeln(f2,'java -jar "apktool.jar" d "%~dp0res\app\',m[i],'" "%~dp0res\app\',w[i],'"');
writeln(f2,'if errorlevel 1 goto error',x);
writeln(f2,'goto go',x);
writeln(f2,':error',x);
writeln(f2,'echo.');
writeln(f2,'echo.');
writeln(f2,'echo Warning: Error when decompiling ',m[i]);
writeln(f2,'pause');
writeln(f2,'goto end');
writeln(f2,':go',x);
writeln(f2,'');
writeln(f2,'xcopy "%~dp0acpatch\',res,'\system\app\',w[i],'" "%~dp0res\app\',w[i],'" /y /s');
writeln(f2,'');
writeln(f2,'java -jar "apktool.jar" b "%~dp0res\app\',w[i],'"');
writeln(f2,'if errorlevel 1 goto errorc',x);
writeln(f2,'goto goc',x);
writeln(f2,':errorc',x);
writeln(f2,'echo.');
writeln(f2,'echo.');
writeln(f2,'echo Warning: Error when compiling ',m[i]);
writeln(f2,'pause');
writeln(f2,'goto end');
writeln(f2,':goc',x);
writeln(f2,'');
writeln(f2,'7za a -tzip "%~dp0res\app\',w[i],'\dist\',m[i],'" "%~dp0res\app\',w[i],'\build\apk\resources.arsc" -mx=0');
writeln(f2,'copy "%~dp0res\app\',w[i],'\dist\',m[i],'" "%~dp0tools\update\system\app\"');
end;
writeln(f2,'');
writeln(f2,'7za a -tzip "',update,'-patch.zip" "%~dp0tools\update\system"');
writeln(f2,'pause');
writeln(f2,':end');
writeln(f2,'echo.');
close(f2);
///конец "пишем бат-файл"
exec('patcher.bat');
end.

Features of new version acPatcher:

• modules (i will make modules for some patch... Like a clock in center statusbar) ;)

• acpatch 5

• stability

• additional function