XE6发布文件 在Deployment Manager中添加待发布的文件,Remote Path写入assets\internal\或assets\就可以

XE6发布文件

在Deployment Manager中添加待发布的文件,Remote Path写入assets\internal\或assets\就可以
其中
assets\internal\会把文件发布到TPath.GetDocumentsPath(也就是/data/data/.../files)目录下
assets\会把文件发布到TPath.GetSharedDocumentsPath(也就是/mnt/sdcard/Android/data/.../files)目录下
另外修改了System.StartUpCopy单元,支持设置assets\sdcard\xxx 会把文件发布到/mnt/sdcard/xxx目录下
{ ******************************************************* }
{ }
{ CodeGear Delphi Runtime Library }
{ Copyright(c) 2013-2014 Embarcadero Technologies, Inc. }
{ }
{ ******************************************************* }

///使用说明
///在Deployment Manager中,设置assets\internal\,文件将会发布到TPath.GetDocumentsPath(也就是/data/data/.../files)
///设置assets\会把文件发布到TPath.GetSharedDocumentsPath(也就是/mnt/sdcard/Android/data/.../files)目录下
///设置assets\sdcard\xxx 会把文件发布到/mnt/sdcard/xxx目录下

{$HPPEMIT LINKUNIT}
unit System.StartUpCopy;

interface

uses
  System.SysUtils;

type
  EStartUpCopyException = class(Exception);

implementation

uses
{$IFDEF ANDROID}
  Androidapi.AssetManager,
  Androidapi.NativeActivity,
  Androidapi.IOUtils,
  Posix.Unistd,
  System.RTLConsts,
  Androidapi.ExternalSDCardPath,
{$ENDIF ANDROID}
{$IFDEF IOS}
  iOSapi.Foundation,
{$ENDIF}
  System.IOUtils;

{$IFDEF ANDROID}

type
  TASSETS_TYPE = (atExternal, atInternal, atSDCard);

const
  MAX_BUFF_LEN = 65536;
  ASSETS_ROOT = ‘assets‘;
  ASSETS_ROOT_D = ‘assets‘ + PathDelim;
  ASSETS_ROOT_D_LENGTH = Length(ASSETS_ROOT_D);
  ASSETS_INTERNAL = ‘internal‘;
  ASSETS_INTERNAL_D = ‘internal‘ + PathDelim;
  ASSETS_DEPLOY_DIR = ‘deployinfo‘;
  ASSETS_FILENAME = ‘deployedassets.txt‘;
  ASSETS_FILENAME_PATH = ASSETS_DEPLOY_DIR + PathDelim + ASSETS_FILENAME;

ASSETS_SDCard = ‘sdcard‘;
  ASSETS_SDCard_D = ‘sdcard‘ + PathDelim;
  ASSETS_SDCard_D_LENGTH = Length(ASSETS_SDCard_D);
{$ENDIF ANDROID}
{$IFDEF ANDROID}

function CopyAssetToFile(LAssetManager: PAAssetManager;
  const AssetFolder, AssetName: string; const DestinationRoot, DestFolder,
  FileName: string): Boolean;
var
  OrigFileName, DestFileName, DestinationPath: string;
  ReadCount, WriteCount: Integer;
  LAssetFile: PAAsset;
  FileHandle: THandle;
  Buffer: TBytes;
  M: TMarshaller;
begin
  Result := True;

if AssetFolder = ‘‘ then
    OrigFileName := AssetName
  else
    OrigFileName := IncludeTrailingPathDelimiter(AssetFolder) + AssetName;

if DestFolder <> ‘‘ then
  begin
    DestinationPath := IncludeTrailingPathDelimiter(DestinationRoot) + DestFolder;
    DestFileName := IncludeTrailingPathDelimiter(DestinationRoot) +
      IncludeTrailingPathDelimiter(DestFolder) + FileName;
  end
  else
  begin
    DestinationPath := DestinationRoot;
    DestFileName := IncludeTrailingPathDelimiter(DestinationRoot) + FileName
  end;

if not FileExists(DestFileName) then // do not overwrite files
  begin
    // Second Create an intermediate buffer.
    SetLength(Buffer, MAX_BUFF_LEN);
    LAssetFile := nil;
    try
      if not DirectoryExists(DestinationPath) then
      begin
        if not ForceDirectories(DestinationPath) then
        begin
          Exit(False);
        end;
      end;
      // We have a valid AssetManager. Start
      LAssetFile := AAssetManager_open(LAssetManager, M.AsUtf8(OrigFileName).ToPointer,
        AASSET_MODE_BUFFER);
      if LAssetFile <> nil then
      begin
        FileHandle := FileCreate(DestFileName);
        try
          if FileHandle = THandle(-1) then
          begin
            Exit(False);
          end;
          repeat
            ReadCount := AAsset_read(LAssetFile, @Buffer[0], MAX_BUFF_LEN);
            WriteCount := FileWrite(FileHandle, Buffer, 0, ReadCount);
          until (ReadCount <= 0) or (ReadCount <> WriteCount);
        finally
          FileClose(FileHandle);
        end;
      end
      else
        raise EStartUpCopyException.CreateFmt(SAssetFileNotFound, [OrigFileName]);
    finally
      if (LAssetFile <> nil) then
        AAsset_close(LAssetFile);
      SetLength(Buffer, 0);
    end;
  end;
end;

function ReadAssetsDeployFile(AssetManager: PAAssetManager;
  var FileContent: string): Boolean;
var
  Buffer: array [0 .. MAX_BUFF_LEN - 1] of char;
  LAssetFile: PAAsset;
  ReadCount: Integer;
  M: TMarshaller;
begin
  Result := False;
  LAssetFile := AAssetManager_open(AssetManager, M.AsUtf8(ASSETS_FILENAME_PATH).ToPointer,
    AASSET_MODE_BUFFER);
  if Assigned(LAssetFile) then
  begin
    try
      repeat
        ReadCount := AAsset_read(LAssetFile, @Buffer, MAX_BUFF_LEN);
        if ReadCount > 0 then
          FileContent := FileContent + UTF8Tostring(@Buffer);
      until (ReadCount <= 0);
      Result := True;
    finally
      AAsset_close(LAssetFile);
    end;
  end;
end;

procedure CopyAssetsToFiles;
var
  AssetManager: PAAssetManager;
  RootDir: string;
  InternalPath: string;
  ExternalPath: string;
  SDCardPath: String;

{$REGION ‘CopyAssetFolder‘}
  procedure CopyAssetFolder(const LAssetManager: PAAssetManager;
    const FromFolder, ToFolder: string; IsInternal: TASSETS_TYPE = atExternal);
  var
    LAssetDir: PAAssetDir;
    LFile: MarshaledAString;
    FileName: string;
    M: TMarshaller;
  begin
    // Listing the files on root directory
    LAssetDir := AAssetManager_openDir(LAssetManager, M.AsUtf8(FromFolder).ToPointer);
    if LAssetDir <> nil then
    begin
      try
        LFile := AAssetDir_getNextFileName(LAssetDir);
        while LFile <> nil do
        begin
          FileName := UTF8Tostring(LFile);
          case IsInternal of
            atInternal:
              begin
                CopyAssetToFile(LAssetManager, FromFolder, FileName, InternalPath,
                  ToFolder, FileName);
              end;
            atSDCard:
              begin
                if SDCardPath = ‘‘ then
                  raise EStartUpCopyException.Create(SExternalExtorageNotAvailable);
                CopyAssetToFile(LAssetManager, FromFolder, FileName, SDCardPath, ToFolder,
                  FileName);
              end;
          else
            begin
              if ExternalPath = ‘‘ then
                raise EStartUpCopyException.Create(SExternalExtorageNotAvailable);
              CopyAssetToFile(LAssetManager, FromFolder, FileName, ExternalPath, ToFolder,
                FileName);
            end;
          end;

LFile := AAssetDir_getNextFileName(LAssetDir);
        end;
      finally
        AAssetDir_close(LAssetDir);
      end;
    end;
  end;
{$ENDREGION}
{$REGION ‘CopyAssetFile‘}
  procedure CopyAssetFile(const LAssetManager: PAAssetManager;
    const FromFile, ToFile: string; IsInternal: TASSETS_TYPE = atExternal);
  var
    FileName: string;
    FromFolder: string;
    ToFolder: string;
  begin
    FromFolder := ExtractFilePath(FromFile);
    ToFolder := ExtractFilePath(ToFile);
    FileName := ExtractFilename(FromFile);

case IsInternal of
      atInternal:
        begin
          CopyAssetToFile(LAssetManager, FromFolder, FileName, InternalPath,
            ToFolder, FileName)
        end;
      atSDCard:
        begin
          if SDCardPath = ‘‘ then
            raise EStartUpCopyException.Create(SExternalExtorageNotAvailable);
          CopyAssetToFile(LAssetManager, FromFolder, FileName, SDCardPath, ToFolder,
            FileName);
        end;
    else
      begin
        if ExternalPath = ‘‘ then
          raise EStartUpCopyException.Create(SExternalExtorageNotAvailable);
        CopyAssetToFile(LAssetManager, FromFolder, FileName, ExternalPath, ToFolder,
          FileName);
      end;
    end;

end;
{$ENDREGION}
{$REGION ‘ProcessDeployedFiles‘}
  procedure ProcessDeployedFiles(const LAssetManager: PAAssetManager; LFilesStr: string);
  var
    I: Integer;
    FileName: string;
    AFiles: TArray<string>;
  begin
    AFiles := LFilesStr.Split([string(#13#10)], ExcludeEmpty);
    for I := Low(AFiles) to High(AFiles) do
    begin
      FileName := AFiles[I].Replace(‘\‘, ‘/‘).Replace(‘./‘, ‘‘);
      if FileName.StartsWith(ASSETS_ROOT_D) then
      begin
        FileName := FileName.Substring(ASSETS_ROOT_D_LENGTH);
        if FileName.StartsWith(ASSETS_INTERNAL_D) then
        begin
          CopyAssetFile(AssetManager, FileName,
            FileName.Substring(Length(ASSETS_INTERNAL_D)), atInternal);
        end
        else if FileName.StartsWith(ASSETS_SDCard) then
        begin
          CopyAssetFile(AssetManager, FileName,
            FileName.Substring(ASSETS_SDCard_D_LENGTH), atSDCard);
        end
        else
        begin
          CopyAssetFile(AssetManager, FileName, FileName, atExternal);
        end;
      end;
    end;
  end;
{$ENDREGION}

var
  DeployedFiles: string;
begin
  InternalPath := GetFilesDir;
  ExternalPath := GetExternalFilesDir;
  SDCardPath := GetExternalSDCardPath();

AssetManager := ANativeActivity(System.DelphiActivity^).AssetManager;
  if (AssetManager <> nil) then
  begin
    if ReadAssetsDeployFile(AssetManager, DeployedFiles) then
      ProcessDeployedFiles(AssetManager, DeployedFiles)
    else
    begin
      RootDir := ‘‘;
      CopyAssetFolder(AssetManager, RootDir, RootDir, atExternal);

RootDir := ASSETS_INTERNAL;
      CopyAssetFolder(AssetManager, RootDir, ‘‘, atInternal);

RootDir := ‘StartUp‘;
      CopyAssetFolder(AssetManager, RootDir, RootDir, atExternal);

RootDir := ASSETS_SDCard;
      CopyAssetFolder(AssetManager, RootDir, RootDir, atSDCard);
    end;
  end;
end;

procedure CopyStartUpFiles;
begin
  CopyAssetsToFiles;
end;
{$ELSE !ANDROID}

procedure CopyStartUpFiles;
var
  Source, Destination: string;

procedure DoCopyFiles(const Src: string; const Dst: string);
  var
    SearchRec: TSearchRec;
    Res: Integer;
  begin
    Res := FindFirst(Src + ‘*‘, faAnyFile, SearchRec);
    while Res = 0 do
    begin
      if (SearchRec.Attr and faDirectory) = faDirectory then
      begin
        if (SearchRec.Name <> ‘.‘) and (SearchRec.Name <> ‘..‘) then
        begin
          if ForceDirectories(Dst + SearchRec.Name) then
            // Do the recurse thing...
            DoCopyFiles(Src + SearchRec.Name + PathDelim,
              Dst + SearchRec.Name + PathDelim);
        end;
      end
      else
      begin
        if not FileExists(Dst + SearchRec.Name) then
        begin
          TFile.Copy(Src + SearchRec.Name, Dst + SearchRec.Name, False);
          // copy without overwriting.
        end
      end;
      Res := FindNext(SearchRec);
    end;
  end;
{$IFDEF IOS}

var
  Bundle: NSBundle;
{$ENDIF}
begin
{$IFDEF IOS}
  Bundle := TNSBundle.Wrap(TNSBundle.OCClass.mainBundle);
  Source := UTF8Tostring(Bundle.bundlePath.UTF8String) + PathDelim + ‘StartUp‘ +
    PathDelim;
{$ELSE}
  Source := ExtractFilePath(ParamStr(0)) + ‘StartUp‘ + PathDelim;
{$ENDIF}
  if DirectoryExists(Source) then
  begin
    Destination := GetHomePath + PathDelim;
    DoCopyFiles(Source, Destination);
  end;
end;
{$ENDIF ANDROID}

initialization

begin
  CopyStartUpFiles;
end;

end.

时间: 2024-10-13 09:30:57

XE6发布文件 在Deployment Manager中添加待发布的文件,Remote Path写入assets\internal\或assets\就可以的相关文章

xcode 6中添加预编译pch文件出现问题解决方法

导入pch 文件,要关联pch: 最重要的一步就是,要在pch中添加如下代码: #import <Availability.h> #ifndef __IPHONE_3_0 #warning "This project uses features only available in iOS SDK 3.0 and later." #endif #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundatio

使用资源文件(内存)中的字体 或 使用文件中的字体

// 一.使用资源文件(内存)中的字体 System.Runtime.InteropServices.GCHandle hObject = System.Runtime.InteropServices.GCHandle.Alloc(Properties.Resources.QuartzMS, System.Runtime.InteropServices.GCHandleType.Pinned); IntPtr intptr = hObject.AddrOfPinnedObject(); Syst

iis中添加视频播放支持mp4文件、flv文件等

今天在ftp上传了一个mp4的文件,发现播放器播放不了,找个本地文件替换了发现可以正常播放,魅力网络为此在浏览器中直接输入mp4的url发现无法显示网页,于是怀疑是服务器的问题,可能是没添加这个视频的格式支持. 所以进入服务器打开iis,添加MIME类型属性就可以了 这样再访问mp4url就出现了mp4的下载页面 不再是无法打开了

在项目中添加全局的 pch 文件

说明,本片博文仅仅是方便自己以后在添加 pch 文件的配置时候参照使用,担心一些配置的路径由于时间而遗忘. (1)建一个 pch 文件 注意下面要 在 Targets 后打上 对号 (2)对该文件进行一些配置 选中项目工程文件,操作如下图所示: (3)常见的错误的处理 大多引入路径的时候,写的完全如上,但是编译之后还是会报错,这时候再次打开我们写的路径,就会发现路径是重复引用了,这时候将重复的引用删除掉,再次编译就OK. 另外,如果是系统的文件,我们在 pch 文件里引入的时候,注意要用 <>

intellij idea中,右键新建文件中添加jsp格式的文件

最近在 学习使用intellij idea,在编写webapp类型的project时,新建中找不到jsp类型,下面是我总结的解决步骤,希望可以帮你解决同样的问题. 按照标注的编号,可以添加到新建的文本类型中去,如果添加后,发现还没有,可以试着重启intellij idea或者电脑,这样应该就有了(我的就是重启之后出现的). 其实在这里找到jsp页面的初始模板后,我们可以根据自己的需要更改,新建jsp页面中的内容,这样新建后的内容,更符合自己的需要,方便使用.

在myeclipse等IDE中添加本地的dtd文件

针对没有网络无法正确引入dtd而使用不了提示的问题 (配置完后重启IDE)   window->perferences- > 搜索xml c 找到xml catalog 右边点击 add  来到此界面 其中 Location  dta文件路径 key type  必须选择 URI key  内容为约束文件中的约束行的 URL  例如, <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configu

Xcode 6中添加预编译pch文件

1.新建一个PCH文件 2.修改buildsetting配置文件 在搜索框里输入prefix搜索一下,比较好找 (1)将绿色部分,也就是Precompile Prefix Header的值设置为YES (2)修改Prefix Header的路径 红色部分为TARGETS的名字,黄色部分为所建的pch文件的名字. TARGETS 3.pch文件 添加代码 #ifdef __OBJC__ #import #endif

Web网页中添加视频播放处理

最近刚好做一个网站视频播放的功能,在此总结: 自己的方法(支持mp4,ogg,mvk格式): <%--宣传视频--%> <!-- One Third Box Start --> <%--属性 值 描述--%> <%--autoplay autoplay 如果出现该属性,则视频在就绪后马上播放.--%> <%--controls controls 如果出现该属性,则向用户显示控件,比如播放按钮.--%> <%--height pixels 设

VS2010发布web应用程序详解(解决发布丢失非代码文件的问题)

首先需要项目可以生成成功. 右键项目名称,选择[发布] 此时弹出发布选项界面, 我们此处选择发布方法为[文件系统] 选择好[目标位置] 选择[发布前删除所有现有文件] 点击[发布],既可以在目标位置发布好程序文件. 这里的文件,不带cs文件,只有前台文件.dll等文件,避免发布后源代码的泄露. 但是,有时候我们在项目中添加了一些模板文件,但是发布以后,没有将这些文件也给复制过去,对于这种情况,我们需要特殊处理下这些文件属性 右键对应文件,在文件属性中,将生成操作字段设置为[内容[ 此时,发布OK