본문 바로가기

파이어몽키

[안드로이드/iOS] 이미 배포(Deployment)된 파일 업데이트 하기

사운드, 이미지, 텍스트 파일을 최초배포하고, 변경된 파일을 다시 배포할 경우 덮어쓰기(overwrite)가 되지않는 이슈가 있습니다.(10 시애틀. 2016년 3월) 해당 증상은 안드로이드와 iOS 모두 해당됩니다.

해당 이슈는 파일을 배포하는 System.StartUpCopy.pas에 구현된 내용을 살펴보니 배포 대상파일이 있는 경우(FileExist) 배포를 진행하지 않도록 구현되어 있습니다.


위 이슈를 해결하는 방법은 3가지 정도로 생각해볼 수 있습니다.

1, System.StartUpCopy.pas를 수정하는 방법

2, 업데이트할 파일을 새로운 이름으로 배포하고, 앱 시작시 기존 파일로 덮어쓰는 방법

3, 파일을 앱과 함께 최초 배포 후, 파일 변경이 필요할 경우 인터넷 등을 통해 자동 업데이트 하는 방법


1, System.StartUpCopy.pas를 수정하는 방법

http://qc.embarcadero.com/wc/qcmain.aspx?d=125481 링크를 방문해 Xavier Dufaure de Citres 글을 참고해 수정할 수 있습니다.

Xavier Dufaure de Citres at 12/14/2014 3:10:58 PM -
Here is a workaround on Android:
* modify System.StartUpCopy
   - in the interface section add "Var ASSET_OVERWRITE : Boolean = false;"
   - in the interface section exopose "procedure CopyStartUpFiles;"
   - in the CopyAssetToFile change "if (not FileExists(DestFileName)) then" by "if (not FileExists(DestFileName)) or ASSET_OVERWRITE then"

* in your own code, store in the preference file the last version the user ran. If the current version is newer do
  if optLastVersionRan<Version then
  Begin
    ASSET_OVERWRITE := true;
    CopyStartUpFiles;
    ASSET_OVERWRITE := false;
  End;

On the 1st installation the data will be copied twice (no biggy), on update the file will be overwritten.

Note for iOS: i find out that deploying the files i need in ".\Data\" is much better: it put the file directly in the bundle, this way the file are not archived (i got my app rejected because i had 12 Mb of data that was archived). Of course these files can only be read only.


2, 업데이트할 파일을 새로운 이름으로 배포하고, 앱 시작시 기존 파일로 덮어쓰는 방법 

배포파일이 업데이트 되면 새로운 파일명으로 배포 후 앱 시작 시 원래파일로 덮어쓰는 방식입니다.

위 이미지와 같이, "deploy.txt" 파일 배포 시 remote name을 "deploy_2.txt"로 배포했습니다.


프로젝트에는 아래와 같은 코드를 구현했습니다.(코드에 대한 설명은 생략합니다.)

uses
  System.IOUtils;

procedure TForm1.Button1Click(Sender: TObject);
var
  Path: string;
begin
  Path := TPath.Combine(TPath.GetDocumentsPath, 'deploy.txt');
  Memo1.Lines.LoadFromFile(Path);
end;

procedure TForm1.DeployFileUpdate(const AFilename, AUpdateFilename: string);
var
  OrgPath, UptPath: string;
begin
  OrgPath := TPath.Combine(TPath.GetDocumentsPath, AFilename);
  UptPath := TPath.Combine(TPath.GetDocumentsPath, AUpdateFilename);

  if TFile.Exists(UptPath) then
  begin
    if TFile.Exists(OrgPath) then
      TFIle.Delete(OrgPath);
    TFile.Move(UptPath, OrgPath);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DeployFileUpdate('deploy.txt',  'deploy_2.txt');
//  DeployFileUpdate('sound1.wav',  'sound1_2.wav');
//  DeployFileUpdate('env.ini',     'env_2.ini');
end;


3, 파일을 앱과 함께 최초 배포 후, 파일 변경이 필요할 경우 인터넷 등을 통해 자동 업데이트 하는 방법

배포파일 자동 업데이트는 파일별 버전관리가 필요하며, 업데이트 파일을 내려주는 서버가 필요합니다.

앱 실행 시 배포파일 버전을  서버에서 확인 후 업데이트할 파일이 있으면, Http, FTP 등으로 파일을 다운로드해 배포파일을 교채하는 방식입니다.

웹상의 파일을 다운로드 받는 방법은 아래 링크를 참고할 수 있습니다.

참고링크


  • 모바일(iOS, Android)에서 사용자 파일 배포 및 사용 : http://blog.hjf.pe.kr/104