Новичок
Профиль
Группа: Участник
Сообщений: 35
Регистрация: 19.6.2009
Репутация: нет Всего: нет
|
Пытаюсь написать инсталлер для программы... Создал файл Install.RES в программе начинаю извлечение но выдает ошибку resourse index1 not found в файле classes вот в этой процедуре | Код | procedure Error; begin raise EResNotFound.CreateFmt(SResNotFound, [Name]); end;
|
Вот мой код | Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, filectrl, ShlObj, ActiveX, ComObj, XPMan, ComCtrls;
type TForm1 = class(TForm) Panel1: TPanel; Splitter1: TSplitter; GroupBox1: TGroupBox; LicMemo: TMemo; PathEdit: TLabeledEdit; SelectPathButton: TButton; InstallButton: TBitBtn; ExitButton: TBitBtn; XPManifest1: TXPManifest; RichEdit1: TRichEdit; procedure ExitButtonClick(Sender: TObject); procedure InstallButtonClick(Sender: TObject); procedure SelectPathButtonClick(Sender: TObject); procedure CreateShotCut(SourceFile, ShortCutName, SourceParams: String); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CreateShotCut(SourceFile, ShortCutName, SourceParams: String); var IUnk: IUnknown; ShellLink: IShellLink; ShellFile: IPersistFile; tmpShortCutName: string; WideStr: WideString; i: Integer; begin IUnk := CreateComObject(CLSID_ShellLink); ShellLink := IUnk as IShellLink; ShellFile := IUnk as IPersistFile;
ShellLink.SetPath(PChar(SourceFile)); ShellLink.SetArguments(PChar(SourceParams)); ShellLink.SetWorkingDirectory(PChar(ExtractFilePath(SourceFile)));
ShortCutName := ChangeFileExt(ShortCutName,'.lnk'); if fileexists(ShortCutName) then begin ShortCutName := copy(ShortCutName,1,length(ShortCutName)-4); i := 1; repeat tmpShortCutName := ShortCutName +'(' + inttostr(i)+ ').lnk'; inc(i); until not fileexists(tmpShortCutName); WideStr := tmpShortCutName; end else WideStr := ShortCutName; ShellFile.Save(PWChar(WideStr),False); end;
procedure ExtractRes(ResType,ResName,ResNewName:String); var Res:TResourceStream; begin Res:=TResourceStream.Create(hInstance,Resname,Pchar(ResType)); Res.SavetoFile(ResNewName); Res.Free; end;
function GetPath(mes: string):string; var Root: string; pwRoot : PWideChar; Dir: string; begin Root:= ''; GetMem(pwRoot,(Length(Root)+1)*2); pwRoot:=StringToWideChar(Root,pwRoot,MAX_PATH*2); if SelectDirectory(mes,pwRoot,Dir)then // функция SelectDirectory определена в filectrl if length(Dir)=2 then GetPath:=Dir+'\' else GetPath := Dir else GetPath:=''; end;
procedure TForm1.ExitButtonClick(Sender: TObject); begin if MessageBox(form1.Handle,'Вы действительно хотите выйти?','Маленький вопрос...',MB_YESNO or MB_ICONQUESTION)=ID_YES then Close; end;
procedure Extract; begin with Form1 do begin
ExtractRes('EXEFILE','Index1',PathEdit.Text+'\best.tv'); ExtractRes('EXEFILE','Index2',PathEdit.Text+'\chat.exe'); ExtractRes('EXEFILE','Index3',PathEdit.Text+'\conf.txt'); ExtractRes('EXEFILE','Index4',PathEdit.Text+'\film.exe'); ExtractRes('EXEFILE','Index6',PathEdit.Text+'\OnlainMovie'); ExtractRes('EXEFILE','Index7',PathEdit.Text+'\OnlainMovie.exe'); ExtractRes('EXEFILE','Index8',PathEdit.Text+'\Project1.res'); ExtractRes('EXEFILE','Index9',PathEdit.Text+'\radio.exe'); ExtractRes('EXEFILE','Index10',PathEdit.Text+'\tv.exe'); ExtractRes('EXEFILE','Index11',PathEdit.Text+'\btn\chat.png'); ExtractRes('EXEFILE','Index12',PathEdit.Text+'\btn\chat1.png'); ExtractRes('EXEFILE','Index13',PathEdit.Text+'\btn\film.png'); ExtractRes('EXEFILE','Index14',PathEdit.Text+'\btn\film1.png'); ExtractRes('EXEFILE','Index15',PathEdit.Text+'\btn\radi.png'); ExtractRes('EXEFILE','Index16',PathEdit.Text+'\btn\radi1.png'); ExtractRes('EXEFILE','Index17',PathEdit.Text+'\btn\tv.png'); ExtractRes('EXEFILE','Index18',PathEdit.Text+'\btn\tv1.png'); ExtractRes('EXEFILE','Index19',PathEdit.Text+'\img\11.jpg'); ExtractRes('EXEFILE','Index20',PathEdit.Text+'\img\1.png'); ExtractRes('EXEFILE','Index21',PathEdit.Text+'\img\112.png'); ExtractRes('EXEFILE','Index22',PathEdit.Text+'\img\1123.png'); ExtractRes('EXEFILE','Index23',PathEdit.Text+'\img\1124.png'); ExtractRes('EXEFILE','Index24',PathEdit.Text+'\img\1125.png'); ExtractRes('EXEFILE','Index25',PathEdit.Text+'\img\1306939571_serach.jpg'); ExtractRes('EXEFILE','Index26',PathEdit.Text+'\img\42911223.png'); ExtractRes('EXEFILE','Index27',PathEdit.Text+'\img\429112232.png'); ExtractRes('EXEFILE','Index28',PathEdit.Text+'\img\chat.png'); ExtractRes('EXEFILE','Index29',PathEdit.Text+'\img\ctb.jpg'); ExtractRes('EXEFILE','Index30',PathEdit.Text+'\img\exit.png'); ExtractRes('EXEFILE','Index31',PathEdit.Text+'\img\exit2.png'); ExtractRes('EXEFILE','Index32',PathEdit.Text+'\img\film.png'); ExtractRes('EXEFILE','Index33',PathEdit.Text+'\img\fon.png'); ExtractRes('EXEFILE','Index34',PathEdit.Text+'\img\fon1.png'); ExtractRes('EXEFILE','Index35',PathEdit.Text+'\img\fon2.PNG'); ExtractRes('EXEFILE','Index36',PathEdit.Text+'\img\ictv.jpg'); ExtractRes('EXEFILE','Index37',PathEdit.Text+'\img\inter1.jpg'); ExtractRes('EXEFILE','Index38',PathEdit.Text+'\img\minus.png'); ExtractRes('EXEFILE','Index39',PathEdit.Text+'\img\new.jpg'); ExtractRes('EXEFILE','Index40',PathEdit.Text+'\img\NTN.jpg'); ExtractRes('EXEFILE','Index41',PathEdit.Text+'\img\plaer.png'); ExtractRes('EXEFILE','Index42',PathEdit.Text+'\img\radio.png'); ExtractRes('EXEFILE','Index43',PathEdit.Text+'\img\search.png'); ExtractRes('EXEFILE','Index44',PathEdit.Text+'\img\search1.png'); ExtractRes('EXEFILE','Index45',PathEdit.Text+'\img\search2.png'); ExtractRes('EXEFILE','Index46',PathEdit.Text+'\img\tet.jpg'); ExtractRes('EXEFILE','Index47',PathEdit.Text+'\img\TONIS.jpg'); ExtractRes('EXEFILE','Index48',PathEdit.Text+'\img\tv.png'); ExtractRes('EXEFILE','Index49',PathEdit.Text+'\img\UT1.jpg'); ExtractRes('EXEFILE','Index50',PathEdit.Text+'\poster\img1.jpg'); ExtractRes('EXEFILE','Index51',PathEdit.Text+'\poster\img2.png'); ExtractRes('EXEFILE','Index52',PathEdit.Text+'\poster\img3.jpg'); end; end;
function GetSpecialPath(CSIDL: word): string; var s: string; begin SetLength(s, MAX_PATH); if not SHGetSpecialFolderPath(0, PChar(s), CSIDL, true) then s := ''; result := PChar(s); end;
procedure TForm1.InstallButtonClick(Sender: TObject); var s4,s5:string; WorkTable:String; Find:_WIN32_FIND_DATAA; P:PItemIDList; C:array [0..1000] of char; begin CreateDirectory(Pchar(PathEdit.Text+'\btn'), nil); CreateDirectory(Pchar(PathEdit.Text+'\img'), nil); CreateDirectory(Pchar(PathEdit.Text+'\poster'), nil); s4:=GetSpecialPath(CSIDL_PROGRAMS); s5:=GetSpecialPath(CSIDL_DESKTOPDIRECTORY);
try if (length(PathEdit.Text)>3)and(PathEdit.Text[2]=':')and(PathEdit.Text[3]='\') then /// контроль правильности имени папки begin PathEdit.Enabled:=false; //отключаем контролы, во время инсталляции щелкать по ним вовсе не желательно, хоть это и не принципиальный момент в программе... SelectPathButton.Enabled:=false; ExitButton.Enabled:=false; InstallButton.Enabled:=false; if not DirectoryExists(PathEdit.Text)then mkdir(PathEdit.Text); /// если не существует директории, то создаем Extract; /// собственно извлечение файлов MessageBox(form1.Handle,'Программа установлена...','Информация для размышления...',MB_OK or MB_ICONINFORMATION); close; end else MessageBox(form1.Handle,'Введите имя папки...','Предупреждение...',MB_OK or MB_ICONWARNING); except MessageBox(form1.Handle,'Неизвестная ошибка !','Ошибка...',MB_OK or MB_ICONERROR); close; end;
if SHGetSpecialFolderLocation(Handle,CSIDL_PROGRAMS,p)=NOERROR then begin SHGetPathFromIDList(P,C); WorkTable:=StrPas(C)+'\OnlainMovie'; end;
if not DirectoryExists(WorkTable) then MkDir(WorkTable); // создание ярлыка с помощью вышеприведенной процедуры CreateShotCut(PathEdit.Text+'\OnlainMovie.exe', WorkTable+'\'+ExtractFileName(PathEdit.Text+'\OnlainMovie.exe'), '');
if SHGetSpecialFolderLocation(Handle,CSIDL_DESKTOP,p)=NOERROR then begin SHGetPathFromIDList(P,C); WorkTable:=StrPas(C)+'\'; end;
if not DirectoryExists(WorkTable) then MkDir(WorkTable); // создание ярлыка с помощью вышеприведенной процедуры CreateShotCut(PathEdit.Text+'\OnlainMovie.exe', WorkTable+'\'+ExtractFileName(PathEdit.Text+'\OnlainMovie.exe'), '');
end;
procedure TForm1.SelectPathButtonClick(Sender: TObject); var path:string; begin Path := GetPath('Выберите папку'); if Path<>'' then PathEdit.Text:=Path; end;
end.
|
что не так?
|