Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Аватара для Johny777

Ветеран


Сообщения: 649
Благодарности: 444

Профиль | Отправить PM | Цитировать


Serega,
спасибо за функцию. Она быстрее прощупывает папки с большим количеством файлов
только вот вылетала
ошибка
читать дальше »

---------------------------
Ошибка запуска
---------------------------
Строка 1179:

Out Of String Range.
---------------------------
ОК
---------------------------

на строке:
Код: Выделить весь код
  if dir[Length(dir)] <> '\' then
    Insert('\', dir, Length(dir)+1);
а именно при нажатии на кнопку отмена на маленькой форме
форма появляется при таком вот условии
if (GetFileCount(S_UPD, '*_update.exe') > 1) and (GetFileCount(ExpandConstant('{src}\outer\update'), '*_update.exe') > 0) and (S_UPD <> ExpandConstant('{src}\outer\update')) then
те если в пути указываемом в TFolderTreeView файлов больше одного, а в директории по умолчанию - папка Outer рядом с инсталлом - есть хоть один файл
после появления формы при нажатии на кнопку отмена директория TFolderTreeView сбрасывается:
TFolderTreeView(Sender).Directory := ExpandConstant('{src}\outer\update');
вот тут-то и вылетала ошибка
исправил (выделил зелёным):
читать дальше »
Код: Выделить весь код
function GetFileCount(dir, mask: string): Integer;
var
  FindFiles: TFindRec;
begin
  Result := 0;
  if FindFirst(dir +'\' + mask, FindFiles) then
    begin
      repeat
        if FindFiles.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
          case FindFiles.Name of
            {#FNames}: Result := Result + 1;
          end;
      until not FindNext(FindFiles);
      FindClose(FindFiles);
    end;
end;

надеюсь этим как обычно не накосячил (может стоило воспользоваться встроенной AddBackslash ?), хотя вроде по тестам всё в порядке

============================================================================ другой вопрос/просьба
вот процедура рассчёта свободного места

читать дальше »
Код: Выделить весь код
/// свободное место /// начало
var
  Size_Form_Exist: boolean;
  Size_Form: TSetupForm;
  NeedSizeLabel, FreeSizeLabel: TLabel;
  No_Space: boolean;
  One_Game_Selected: boolean;

  half_life_2_russian_gcf: boolean;                  // 1
  half_life_2_buka_russian_gcf: boolean;             // 2
  half_life_2_2007_base_content_gcf: boolean;        // 3
  half_life_2_content_gcf: boolean;                  // 4
 // half_life_2_game_dialog_gcf: boolean;              // 5
  episode_one_2007_content_gcf: boolean;             // 6
  half_life_2_episode_one_gcf: boolean;              // 7
  episodic_2007_shared_gcf: boolean;                 // 8
  episode_1_shared_gcf: boolean;                     // 9
  half_life_2_episode_two_english_gcf: boolean;      // 10
  episode_two_content_gcf: boolean;                  // 11
  episode_two_maps_gcf: boolean;                     // 12
  episode_two_materials_gcf: boolean;                // 13
  portal_english_gcf: boolean;                       // 14
  portal_content_gcf: boolean;                       // 15
  source_2007_binaries_2_gcf: boolean;               // 16
  source_2007_shared_materials_gcf: boolean;         // 17
  source_2007_shared_models_gcf: boolean;            // 18
  source_2007_shared_sounds_gcf: boolean;            // 19
  source_materials_gcf: boolean;                     // 20
  source_models_gcf: boolean;                        // 21
  source_sounds_gcf: boolean;                        // 22
  half_life_2_episode_one_russian_gcf: boolean;      // 23
  half_life_2_episode_two_russian_gcf: boolean;      // 24
  portal_russian_gcf: boolean;                       // 25

procedure Calculate;
var
  NeedSize: Integer;
  iCore_All, iCoreEpisodes: Integer;
  ihl2_Size, ihl2_russian_Size, ihl2_russian_buka_Size: Integer;
  ihl2_ep1_Size, ihl2_ep1_russian_Size: Integer;
  ihl2_ep2_Size, ihl2_ep2_russian_Size, ihl2_ep2_english_Size: Integer;
  iPortal_Size, iPortal_russian_Size, iPortal_english_Size: Integer;
  ihl2_Dir_Size, iep1_Dir_Size, iep2_Dir_Size, iportal_Dir_Size: Integer;

  One_Episode_Selected: boolean;

  i_half_life_2_russian_gcf: Integer;                  // 1
  i_half_life_2_buka_russian_gcf: Integer;             // 2
  i_half_life_2_2007_base_content_gcf: Integer;        // 3
  i_half_life_2_content_gcf: Integer;                  // 4
 // i_half_life_2_game_dialog_gcf: Integer;              // 5
  i_episode_one_2007_content_gcf: Integer;             // 6
  i_half_life_2_episode_one_gcf: Integer;              // 7
  i_episodic_2007_shared_gcf: Integer;                 // 8
  i_episode_1_shared_gcf: Integer;                     // 9
  i_half_life_2_episode_two_english_gcf: Integer;      // 10
  i_episode_two_content_gcf: Integer;                  // 11
  i_episode_two_maps_gcf: Integer;                     // 12
  i_episode_two_materials_gcf: Integer;                // 13
  i_portal_english_gcf: Integer;                       // 14
  i_portal_content_gcf: Integer;                       // 15
  i_source_2007_binaries_2_gcf: Integer;               // 16
  i_source_2007_shared_materials_gcf: Integer;         // 17
  i_source_2007_shared_models_gcf: Integer;            // 18
  i_source_2007_shared_sounds_gcf: Integer;            // 19
  i_source_materials_gcf: Integer;                     // 20
  i_source_models_gcf: Integer;                        // 21
  i_source_sounds_gcf: Integer;                        // 22
  i_half_life_2_episode_one_russian_gcf: Integer;      // 23
  i_half_life_2_episode_two_russian_gcf: Integer;      // 24
  i_portal_russian_gcf: Integer;                       // 25

begin
  if not Size_Form_Exist then
  begin
    if not Param and not Game_From_INI_Selected then
    begin
      half_life_2_russian_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2_russian.gcf');
      half_life_2_buka_russian_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2 buka russian.gcf');
      half_life_2_2007_base_content_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2 2007 base content.gcf');
      half_life_2_content_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2 content.gcf');
    // half_life_2_game_dialog_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2 game dialog.gcf');
      episode_one_2007_content_gcf := FileExists(WizardForm.DirEdit.Text + '\episode one 2007 content.gcf');
      half_life_2_episode_one_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2 episode one.gcf');
      episodic_2007_shared_gcf := FileExists(WizardForm.DirEdit.Text + '\episodic 2007 shared.gcf');
      episode_1_shared_gcf := FileExists(WizardForm.DirEdit.Text + '\episode 1 shared.gcf');
      half_life_2_episode_two_english_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2 episode two english.gcf');
      episode_two_content_gcf := FileExists(WizardForm.DirEdit.Text + '\episode two content.gcf');
      episode_two_maps_gcf := FileExists(WizardForm.DirEdit.Text + '\episode two maps.gcf');
      episode_two_materials_gcf := FileExists(WizardForm.DirEdit.Text + '\episode two materials.gcf');
      portal_english_gcf := FileExists(WizardForm.DirEdit.Text + '\portal english.gcf');
      portal_content_gcf := FileExists(WizardForm.DirEdit.Text + '\portal content.gcf');
      source_2007_binaries_2_gcf := FileExists(WizardForm.DirEdit.Text + '\source 2007 binaries 2.gcf');
      source_2007_shared_materials_gcf := FileExists(WizardForm.DirEdit.Text + '\source 2007 shared materials.gcf');
      source_2007_shared_models_gcf := FileExists(WizardForm.DirEdit.Text + '\source 2007 shared models.gcf');
      source_2007_shared_sounds_gcf := FileExists(WizardForm.DirEdit.Text + '\source 2007 shared sounds.gcf');
      source_materials_gcf := FileExists(WizardForm.DirEdit.Text + '\source materials.gcf');
      source_models_gcf := FileExists(WizardForm.DirEdit.Text + '\source models.gcf');
      source_sounds_gcf := FileExists(WizardForm.DirEdit.Text + '\source sounds.gcf');
      half_life_2_episode_one_russian_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2 episode one russian.gcf');
      half_life_2_episode_two_russian_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2 episode two russian.gcf');
      portal_russian_gcf := FileExists(WizardForm.DirEdit.Text + '\portal russian.gcf');
    end;
    
    Size_Form := CreateCustomForm();
    with Size_Form do
    begin
      ClientWidth := ScaleX(187);
      ClientHeight := ScaleY(54);
      BorderIcons := [];
      Caption := ExpandConstant('{cm:SFormCaption}');
      Left := WizardForm.Left + ScaleX(346);
      Top := WizardForm.Top - ScaleY(87);
      DeleteMenu(GetSystemMenu(Size_Form.Handle,False), $F060,0); /// сделать кнопку "закрыть" неактивной
      SetClassLong(Size_Form.Handle, -26, GetClassLong(Size_Form.Handle, -26) or $200); /// блокировка комбинации alt + f4
      if not No_Backgr_Pic then FormStyle := fsStayOnTop;

      NeedSizeLabel := TLabel.Create(nil)
      with NeedSizeLabel do
      begin
        Parent := Size_Form;
        SetBounds(ScaleX(7), ScaleY(1), ScaleX(50), ScaleY(13));
        Caption := ExpandConstant('{cm:Count}');
      end;

      FreeSizeLabel := TLabel.Create(nil)
      with FreeSizeLabel do
      begin
        Parent := Size_Form;
        SetBounds(ScaleX(7), ScaleY(23), ScaleX(50), ScaleY(13));
        Caption := ExpandConstant('{cm:Analyze}');
      end;

      GetSpaceOnDisk(ExtractFileDrive(WizardForm.DirEdit.Text), True, FreeMB, TotalMB);
      FreeSizeLabel.Caption := ExpandConstant('{cm:Free_Space} ') + FloatToStr(round(FreeMB/1024*100)/100) + ExpandConstant(' {cm:Gb}');

      Show;
      Repaint;
      Size_Form_Exist := True;
    end;
    SendMessage(WizardForm.Handle,$0112,$F012,0); // нажимаем на окно, чтоб стало активным
  end;
  ////////////////////////////////////////////

  One_Episode_Selected := (hl2_ru_RadioButton.Checked and hl2_ru_RadioButton.Enabled) or (hl2_ep1_ru_RadioButton.Checked and hl2_ep1_ru_RadioButton.Enabled) or (hl2_ep2_ru_RadioButton.Checked and hl2_ep2_ru_RadioButton.Enabled);



  //  half_life_2_game_dialog_gcf
  if hl2_CheckBox.Checked and hl2_CheckBox.Enabled then /// эксклюзивные  файлы халфы 2
  begin
    if not DirExists(WizardForm.DirEdit.Text + '\common\half-life 2') then ihl2_Dir_Size := 1903 else ihl2_Dir_Size := 0;
    if not half_life_2_buka_russian_gcf then i_half_life_2_buka_russian_gcf := 428 else i_half_life_2_buka_russian_gcf := 0; 
    if not half_life_2_2007_base_content_gcf then i_half_life_2_2007_base_content_gcf := 498 else i_half_life_2_2007_base_content_gcf := 0;
    if not half_life_2_content_gcf then i_half_life_2_content_gcf := 841 else i_half_life_2_content_gcf := 0; /// точно

    if (hl2_buka_CheckBox.Checked and hl2_buka_CheckBox.Enabled) then  ihl2_russian_buka_Size := i_half_life_2_buka_russian_gcf else  ihl2_russian_buka_Size := 0; /// бука

    ihl2_Size := i_half_life_2_2007_base_content_gcf + i_half_life_2_content_gcf + ihl2_Dir_Size // где 1844 это размер папки с файлами
  end;



  if hl2_ep1_CheckBox.Checked and hl2_ep1_CheckBox.Enabled then /// эксклюзивные файлы эпизода 1
  begin
    if not DirExists(WizardForm.DirEdit.Text + '\common\half-life 2 episode one') then iep1_Dir_Size := 142 else iep1_Dir_Size := 0;
    if not episode_one_2007_content_gcf then i_episode_one_2007_content_gcf := 246 else i_episode_one_2007_content_gcf := 0; /// точно
    if not half_life_2_episode_one_gcf then i_half_life_2_episode_one_gcf := 606 else i_half_life_2_episode_one_gcf := 0; /// точно

    ihl2_ep1_Size := i_episode_one_2007_content_gcf + i_half_life_2_episode_one_gcf + iep1_Dir_Size
  end;



  if hl2_ep2_CheckBox.Checked and hl2_ep2_CheckBox.Enabled then /// зксклюзивные файлы эпизода 2
  begin
    if not DirExists(WizardForm.DirEdit.Text + '\common\half-life 2 episode two') then iep2_Dir_Size := 332 else iep2_Dir_Size := 0;
    if not half_life_2_episode_two_russian_gcf then i_half_life_2_episode_two_russian_gcf := 303 else i_half_life_2_episode_two_russian_gcf := 0;
    if not half_life_2_episode_two_english_gcf then i_half_life_2_episode_two_english_gcf := 500 else i_half_life_2_episode_two_english_gcf := 0; 
    if not episode_two_content_gcf then i_episode_two_content_gcf := 1442 else i_episode_two_content_gcf := 0;
    if not episode_two_maps_gcf then i_episode_two_maps_gcf := 675 else i_episode_two_maps_gcf := 0;
    if not episode_two_materials_gcf then i_episode_two_materials_gcf := 670 else i_episode_two_materials_gcf := 0;

    if (hl2_ep2_ru_RadioButton.Checked and hl2_ep2_ru_RadioButton.Enabled) then ihl2_ep2_russian_Size := i_half_life_2_episode_two_russian_gcf else ihl2_ep2_russian_Size := 0; /// русская озвучка относится только ко второму эпизоду
    if (hl2_ep2_en_RadioButton.Checked and hl2_ep2_en_RadioButton.Enabled) or (hl2_ep2_ru_en_RadioButton.Checked and hl2_ep2_ru_en_RadioButton.Enabled) then ihl2_ep2_english_Size := i_half_life_2_episode_two_english_gcf else  ihl2_ep2_english_Size := 0

    ihl2_ep2_Size := i_episode_two_content_gcf + i_episode_two_maps_gcf + i_episode_two_materials_gcf + iep2_Dir_Size
  end;



  if portal_CheckBox.Checked and portal_CheckBox.Enabled then // экссклюзив файлы Портала
  begin
    if not DirExists(WizardForm.DirEdit.Text + '\common\portal') then iportal_Dir_Size := 121 else iportal_Dir_Size := 0;
    if not portal_russian_gcf then i_portal_russian_gcf := 111 else i_portal_russian_gcf := 0; /// точно
    if not portal_english_gcf then i_portal_english_gcf := 160 else i_portal_english_gcf := 0; /// точно
    if not portal_content_gcf then i_portal_content_gcf := 1049 else i_portal_content_gcf := 0; /// точно

    if (portal_ru_RadioButton.Checked and portal_ru_RadioButton.Enabled) then iPortal_russian_Size := i_portal_russian_gcf else  iPortal_russian_Size := 0;
    if (portal_en_RadioButton.Checked and portal_en_RadioButton.Enabled) or (portal_ru_en_RadioButton.Checked and portal_ru_en_RadioButton.Enabled) then iPortal_english_Size := i_portal_english_gcf else iPortal_english_Size := 0;

    iPortal_Size := i_portal_content_gcf + iportal_Dir_Size
  end;


  /// ядро ресурсов всех 4-х игр
  if One_Game_Selected then
  begin
    if not source_2007_binaries_2_gcf then i_source_2007_binaries_2_gcf := 135 else i_source_2007_binaries_2_gcf := 0; /// точно
    if not source_2007_shared_materials_gcf then i_source_2007_shared_materials_gcf := 985 else i_source_2007_shared_materials_gcf := 0; /// точно
    if not source_2007_shared_models_gcf then i_source_2007_shared_models_gcf := 148 else i_source_2007_shared_models_gcf := 0;  /// точно
    if not source_2007_shared_sounds_gcf then i_source_2007_shared_sounds_gcf := 2 else i_source_2007_shared_sounds_gcf := 0; /// точно
    if not source_materials_gcf then i_source_materials_gcf := 1047 else i_source_materials_gcf := 0;  /// точно
    if not source_models_gcf then i_source_models_gcf := 449 else i_source_models_gcf := 0;  /// точно
    if not source_sounds_gcf then i_source_sounds_gcf := 975 else i_source_sounds_gcf := 0;  /// точно

    iCore_All := i_source_2007_binaries_2_gcf + i_source_2007_shared_materials_gcf + i_source_2007_shared_models_gcf + i_source_2007_shared_sounds_gcf + i_source_materials_gcf + i_source_models_gcf + i_source_sounds_gcf;
  end;



  if ((hl2_ep1_CheckBox.Checked and hl2_ep1_CheckBox.Enabled) or (hl2_ep2_CheckBox.Checked and hl2_ep2_CheckBox.Enabled)) then /// ядро ресурсов эпизодов и только их
  begin
    if not episodic_2007_shared_gcf then i_episodic_2007_shared_gcf := 273 else i_episodic_2007_shared_gcf := 0; 
    if not episode_1_shared_gcf then i_episode_1_shared_gcf := 1229 else i_episode_1_shared_gcf := 0;

    iCoreEpisodes := i_episode_1_shared_gcf + i_episodic_2007_shared_gcf
  end;



  if One_Episode_Selected then  /// файл hl2_russian.gcf относится ко всем 3-м играм
  begin
    if not half_life_2_russian_gcf then i_half_life_2_russian_gcf := 784 else i_half_life_2_russian_gcf := 0; 

    ihl2_russian_Size := i_half_life_2_russian_gcf;
  end;



  if (hl2_ep1_ru_RadioButton.Checked and hl2_ep1_ru_RadioButton.Enabled) or (hl2_ep2_ru_RadioButton.Checked and hl2_ep2_ru_RadioButton.Enabled) then /// half-life 2 episode one russian.gcf относится к 2-м эпизодам
  begin
    if not half_life_2_episode_one_russian_gcf then i_half_life_2_episode_one_russian_gcf := 539 else i_half_life_2_episode_one_russian_gcf := 0; /// точно

    ihl2_ep1_russian_Size := i_half_life_2_episode_one_russian_gcf
  end;



  NeedSize := iCore_All + iCoreEpisodes + ihl2_Size + ihl2_russian_Size + ihl2_russian_buka_Size + ihl2_ep1_Size + ihl2_ep1_russian_Size + ihl2_ep2_Size + ihl2_ep2_russian_Size + ihl2_ep2_english_Size + iPortal_russian_Size + iPortal_english_Size + iPortal_Size;


  if FreeMB < NeedSize then
  begin
    if WizardForm.CurPageID = wpSelectDir then WizardForm.NextButton.Enabled := False;

    NeedSizeLabel.Font.Color := $48c1ca;

    No_Space := True;
  end
  else
  begin
    if WizardForm.CurPageID = wpSelectDir then WizardForm.NextButton.Enabled := not IsStringCyrillic(WizardForm.DirEdit.Text);

    NeedSizeLabel.Font.Color := clWindowText;

    No_Space := False;
  end;

  NeedSizeLabel.Caption := ExpandConstant('{cm:Needed_Size} ') + FloatToStr(round(NeedSize/1024*100)/100) + ExpandConstant(' {cm:Gb}'); // + IntToStr(NeedSize) + ' Mb';
end;
/// конец


где Param(чекбокс отмечен через параметр запуска) и Game_From_INI_Selected(чекбокс отмечен из ключа рядом лежащего ини) это булев переменные
если одна из них True, то длинный рассчёт
...
half_life_2_russian_gcf := FileExists(WizardForm.DirEdit.Text + '\half-life 2_russian.gcf');
...
обрабатывается в InitializeWizard и в WizardFormDirEditOnChange
укоротил и упростил эту процедуру как мог

если есть ещё способы по ускорению скорости её работы, то скажите пожалуйста

Последний раз редактировалось Johny777, 08-08-2012 в 12:59.

Это сообщение посчитали полезным следующие участники:

Отправлено: 12:28, 08-08-2012 | #553