2017-05-24 17 views
2

다른 줄 앞에 파일/서식 파일에 줄을 추가하려면 어떻게해야합니까?Inno 설치 - 특정 줄 앞에 텍스트 파일/서식 파일에 줄을 삽입하십시오 (아직없는 경우)

예를 들어 다음 JS 파일의 경우 과 BELOW THIS LINE 주석 행 사이에 dependencies.push(...) 행이 있는지 확인해야합니다. dependencies.push(...)이없는 경우, 나는 BELOW THIS LINE 주석 라인 전에 추가해야합니다 :

(function(ng) { 
    var dependencies = []; 

    /*DO NOT MODIFY ABOVE THIS LINE!*/ 

    dependencies.push("mxdfNewTransaction.controller.mxdfNewTransactionCtrl"); 

    /*DO NOT MODIFY BELOW THIS LINE!*/ 

    ng.module('prismApp.customizations', dependencies, null); 
})(angular); 

나는 또한 비슷한 HTML 템플릿 파일과 같은 일을해야합니다.

도움 주셔서 감사합니다.

+0

"지정된 다른 줄"- 지정된 방법? 예제를 보여주십시오. –

+0

@ MartinPrikryl 내 질문을 편집했습니다. 이해하는 것이 더 나을 수도 있습니다. –

+0

나는 아직도 당신이 원하는 것을 이해하지 못합니다. 기존의'customizations.js' 파일을 수정하고 있습니까? 또는 설치 프로그램에서 파일을 완전히 만들었습니까? 첫 번째 파일 인 경우 설치 전에 파일이 어떻게 보이고 이후에 어떤 모습이어야합니까? –

답변

1

코드를 삽입 할 지점을 찾으려면 파일을 한 줄씩 파싱해야합니다. 이 같은

뭔가 :

function AddLineToTemplate(
    FileName: string; StartLine, EndLine, AddLine: string): Boolean; 
var 
    Lines: TArrayOfString; 
    Count, I, I2: Integer; 
    Line: string; 
    State: Integer; 
begin 
    Result := True; 

    if not LoadStringsFromFile(FileName, Lines) then 
    begin 
    Log(Format('Error reading %s', [FileName])); 
    Result := False; 
    end 
    else 
    begin 
    State := 0; 

    Count := GetArrayLength(Lines); 
    for I := 0 to Count - 1 do 
    begin 
     Line := Trim(Lines[I]); 
     if (CompareText(Line, StartLine) = 0) then 
     begin 
     State := 1; 
     Log(Format('Start line found at %d', [I])); 
     end 
     else 
     if (State = 1) and (CompareText(Line, AddLine) = 0) then 
     begin 
     Log(Format('Line already present at %d', [I])); 
     State := 2; 
     break; 
     end 
     else 
     if (State = 1) and (CompareText(Line, EndLine) = 0) then 
     begin 
     Log(Format('End line found at %d, inserting', [I])); 
     SetArrayLength(Lines, Count + 1); 
     for I2 := Count - 1 downto I do 
      Lines[I2 + 1] := Lines[I2]; 
     Lines[I] := AddLine; 
     State := 2; 

     if not SaveStringsToFile(FileName, Lines, False) then 
     begin 
      Log(Format('Error writting %s', [FileName])); 
      Result := False; 
     end 
      else 
     begin 
      Log(Format('Modifications saved to %s', [FileName])); 
     end; 

     break; 
     end; 
    end; 

    if Result and (State <> 2) then 
    begin 
     Log(Format('Spot to insert line was not found in %s', [FileName])); 
     Result := False; 
    end; 
    end; 
end; 

당신은 다음과 같이 사용할 수 있습니다 : 유니 코드 파일로 작업 할 때

if AddLineToTemplate(
    'C:\path\to\customizations.js', 
    '/*DO NOT MODIFY ABOVE THIS LINE!*/', 
    '/*DO NOT MODIFY BELOW THIS LINE!*/', 
    ' dependencies.push("mxdfNewTransaction.controller.mxdfNewTransactionCtrl");') then 
begin 
    Log('Success'); 
end 
    else 
begin 
    Log('Failure'); 
end; 

LoadStringsFromFileSaveStringsToFile 제한 조심하십시오. Inno Setup Reading file in Ansi and Unicode encoding을 참조하십시오.