unit _Network;

interface

uses
  Classes, ShellAPI, Windows, SysUtils,
  _SimpleDialog,_NetworkCatalog,_netconst;

type
  TNetwork = class
  private
    { Private 宣言 }
    NetworkEnabled:boolean;
    StartDir:string;
  public
    { Public 宣言 }
    CFG:TCFG;
    NetworkCatalog:TNetworkCatalog;
    MXDRVPDXFileList,FMPMDPCMFileList:TStringList;
    procedure StartOnlineUpdate(UpdateCheckOnly:boolean);
    procedure Startup(_StartDir:string);
    procedure FreeMemory;
    function GetNetworkEnabled:boolean;
    function NetworkEnable:boolean;
    function LoadCFG:boolean;
    function LoadCatalog:boolean;
    procedure LoadFiles(path:string;var TempList:TStrings;cnvSJIS:boolean);
    procedure LoadPCMFileList;
    function MXDRVPlay(const DriverMode:integer):boolean;
    function FMPPlay:boolean;
    function PMDPlay:boolean;
    function SPCPlay:boolean;
    function GetHTTPDataFile(_url,_WriteFilename,msg:string):boolean;
//    function GetHTTPDataFileZip(_url,_WriteFilename,msg:string):boolean;
    function GetHTTPDataFileSZip(_url,_WriteFilename,msg:string):boolean;
    function GetNetworkPDXFilename(PDXFilename:string):string;
    function GetNetworkPCMFilename(PCMFilename:string):string;
  end;

implementation

uses MainWin,
     _const,_MDXWinINI,_SndDrv_const,_SndDrv,_MDXWin_const,_m_Tools,_SZip_Tools,_filebuf;

procedure TNetwork.Startup(_StartDir:string);
begin
  StartDir:=_StartDir;
  NetworkEnabled:=False;
  NetworkCatalog:=TNetworkCatalog.Create;
  MXDRVPDXFileList:=TStringList.Create;
  FMPMDPCMFileList:=TStringList.Create;
end;

procedure TNetwork.FreeMemory;
begin
  NetworkEnabled:=False;
  NetworkCatalog.Free;
  MXDRVPDXFileList.Free;
  FMPMDPCMFileList.Free;
end;

function TNetwork.GetNetworkEnabled:boolean;
begin
  Result:=NetworkEnabled;
end;

function TNetwork.NetworkEnable:boolean;
begin
  if NetworkEnabled=True then begin
    result:=True;
    exit;
  end;

  if LoadCFG=False then begin
    ShowMessage('MDXOnline','ネットワーク基本設定ファイルのダウンロードに失敗しました。');
    result:=False;
    exit;
  end;

  if LoadCatalog=False then begin
    ShowMessage('MDXOnline','ネットワークカタログファイルのダウンロードに失敗しました。');
    result:=False;
    exit;
  end;

  if MainINI.MDXOnlineAutoUpdate=True then StartOnlineUpdate(True);

  NetworkEnabled:=True;
  result:=True;
end;

procedure TNetwork.StartOnlineUpdate(UpdateCheckOnly:boolean);
var
  ExeFilename,InstansFilename:string;
begin
  ExeFilename:=StartDir+'OnlineUpdate.exe';
  InstansFilename:=StartDir+'OnlineUpdate_Instans.exe';
  if FileExists(ExeFilename)=True then begin
    DeleteFile(InstansFilename);
    if FileExists(InstansFilename)=True then begin
      if UpdateCheckOnly=False then begin
        ShowMessage('MDXOnline','オンラインアップデートは既に起動しています。');
      end;
      end else begin
      CopyFile(pchar(ExeFilename),pchar(InstansFilename),False);
      if UpdateCheckOnly=True then begin
        ShellExecute(0,'open',PChar(InstansFilename),pchar('-UpdateCheckOnly'), nil,SW_SHOW);
        end else begin
        ShellExecute(0,'open',PChar(InstansFilename),pchar('-Normal'), nil,SW_SHOW);
      end;
    end;
  end;
end;

function TNetwork.LoadCFG:boolean;
var
  NeedFile:TNeedFile;
begin

  with NeedFile do begin
    Port:=11080;
    Host:='moonlight.servehttp.com';
    if MainINI.MDXOnlineBufferSize<>0 then begin
      BufferSize:=MainINI.MDXOnlineBufferSize;
      end else begin
      BufferSize:=256;
    end;
    URL:='/mdxonline213.cfg';
    UserAgent:='MDXOnline';
    WriteFileSize:=0;
    WriteFileCheckSum:=0;
    WriteFilename:='';
  end;
  Main.HTTPSocket.SetNeedFile(NeedFile);
  Main.HTTPSocket.GetHTTPFile('ネットワーク環境ファイルをダウンロードしています…');

  if Main.HTTPSocket.NetworkResult=ResultSuccess then begin
    result:=True;
    LoadCFGfromBuffer(CFG,Main.HTTPSocket.Buffer,Main.HTTPSocket.BufferCount);
    DeleteFile(NeedFile.WriteFilename);
    with CFG do begin
      UserAgent:=UserAgent+'/'+MDXWinVersion;
{$ifdef mdxwin}
      if MainINI.UseRomeo=True then begin
        UserAgent:=UserAgent+'r';
        end else begin
        if MXDRVgINI.Enabled=True then begin
          UserAgent:=UserAgent+'g';
          end else begin
          UserAgent:=UserAgent+'m';
        end;
      end;
{$else}
      UserAgent:=UserAgent+'a'; // MDXAss
{$endif}
      CatalogURL:=BasePath;
      CatalogBasePath:=StartDir+NetCachePath;
      CatalogSeek:=CatalogBasePath+'catalog.seek';
      RankingURL:=BasePath+'ranking.dat';
      RankingPath:=StartDir+NetCachePath+'ranking.dat';
      PCMFileListURL:=BasePath+'pcmfilelist.dat';
      PCMFileListFilename:=StartDir+NetCachePath+'pcmfilelist.dat';
      MXDRV_PDXPath:=StartDir+NetCachePath+'MXDRV_PDX\';
      FMPPMD_PCMPath:=StartDir+NetCachePath+'FMPPMD_PCM\';
      MusicPath:=StartDir+NetCachePath+'Music\';
      VoteSendURL:=BasePath+'votesend.fnc';
      VoteDataURL:=BasePath+'vote.dat';
      VoteDataFilename:=StartDir+NetCachePath+'vote.dat';
    end;
    end else begin
    result:=False;
  end;
end;

function TNetwork.LoadCatalog:boolean;
var
  FileSize:dword;
  url,WriteFilename:string;
  netres:boolean;
begin
  NetworkCatalog.Init(CFG.CatalogBasePath);

  // まずデータファイルのサイズをCFGファイル内の情報と比較
  if FileExists(NetworkCatalog.GetDataFilename)=True then begin
    FileSize:=GetFileSize(NetworkCatalog.GetDataFilename);
    if CFG.CatalogDataSize<>FileSize then begin
      ShowMessage('MDXOnline','ネットワークキャッシュが更新されました。'+CRLF+'ダウンロードが完了するには数分かかる場合があります。'+CRLF+'しばらくお待ち下さい。');
      DeleteFile(NetworkCatalog.GetIndexFilename);
      DeleteFile(NetworkCatalog.GetDataFilename);
      DeleteFile(NetworkCatalog.GetCatalogFilePath+'catalog.seek');
      DeleteFile(CFG.PCMFileListFilename);
    end;
  end;

  // MDXWinがバージョンアップしたときは、ファイル一覧リストを無条件で削除
  if FileExists(NetworkCatalog.GetCatalogFilePath+'catalog.seek')=True then begin
    FileSize:=GetFileSize(NetworkCatalog.GetCatalogFilePath+'catalog.seek');
    if (FileSize=0) or (FileSize=1) then DeleteFile(NetworkCatalog.GetCatalogFilePath+'catalog.seek');
  end;

  // 全てのファイル(SEEKを除く)が揃っていればキャッシュから読み込み
  if (FileExists(NetworkCatalog.GetIndexFilename)=True) and
     (FileExists(NetworkCatalog.GetDataFilename)=True) and
     (FileExists(CFG.PCMFileListFilename)=True) then begin
    NetworkCatalog.LoadIndex;
    LoadPCMFileList;
    Result:=True;
    exit;
  end;

  // 念のため全部削除
  ForceDirectories(CFG.CatalogBasePath);
  DeleteFile(NetworkCatalog.GetIndexFilename);
  DeleteFile(NetworkCatalog.GetDataFilename);
  DeleteFile(NetworkCatalog.GetCatalogFilePath+'catalog.seek');
  DeleteFile(CFG.PCMFileListFilename);

  // ダウンロード
  url:=CFG.CatalogURL+'catalog.idx';
  WriteFilename:=NetworkCatalog.GetIndexFilename;
  netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークインデックスをダウンロードしています…');
  if netres=False then begin
    Result:=False;
    exit;
  end;

  url:=CFG.CatalogURL+'catalog.dat';
  WriteFilename:=NetworkCatalog.GetDataFilename;
  netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークカタログをダウンロードしています…');
  if netres=False then begin
    Result:=False;
    exit;
  end;

  url:=CFG.PCMFileListURL;
  WriteFilename:=CFG.PCMFileListFilename;
  netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークPCMファイルリストをダウンロードしています…');
  if netres=False then begin
    Result:=False;
    exit;
  end;

  // ダウンロードされたキャッシュから読み込み
  NetworkCatalog.LoadIndex;
  LoadPCMFileList;

  Result:=True;
end;

procedure TNetwork.LoadFiles(path:string;var TempList:TStrings;cnvSJIS:boolean);
begin
  if NetworkEnable=False then exit;

  if length(path)<=3 then begin
    NetworkCatalog.LoadData('\',TempList,cnvSJIS);
    end else begin
    TempList.Add('_ < Directory >  ..');
    NetworkCatalog.LoadData(copy(path,4,255)+'\',TempList,cnvSJIS);
    TempList.Add(TempList[0]);
  end;
end;

function TNetwork.MXDRVPlay(const DriverMode:integer):boolean;
var
  url:string;
  WriteFilename:string;
  netres:boolean;
  PDXFilename:string;
  SetPCMPath:string;
begin
  if (DriverMode<>DriverModeMXDRVm) and (DriverMode<>DriverModeMXDRVg) then begin
    Main.InfomationVisible('不適切なDriverModeエラー');
    Result:=False;
    exit;
  end;

  url:=ConvPath2URL(CFG.BasePath,Main.gFileInfo.GetFullPath);
  WriteFilename:=Main.gFileInfo.GetNetworkDownloadPath;
  DeleteFile(WriteFilename);
  netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークMDXファイルをダウンロードしています…');
  if netres=False then begin
    Main.InfomationVisible('MDXダウンロード失敗');
    Result:=False;
    exit;
  end;

{$ifdef mdxwin}
  SetPCMPath:=CFG.MXDRV_PDXPath;
{$else}
  if Main.gFileInfo.GetNetworkToRealPath=True then begin
    SetPCMPath:=ExtractFilePath(Main.gFileInfo.GetNetworkDownloadPath);
    end else begin
    SetPCMPath:=CFG.MXDRV_PDXPath;
  end;
{$endif}

  PDXFilename:=thChangeFileExt(GetPDXFilename(WriteFilename),'');
  if copy(PDXFilename,1,1)='\' then PDXFilename:=copy(PDXFilename,2,255);
  if PDXFilename<>'' then PDXFilename:=GetNetworkPDXFilename(PDXFilename);
  if PDXFilename<>'' then begin
    url:=CFG.BasePath+CFG.MXDRV_PDXURL+PDXFilename;
    WriteFilename:=SetPCMPath+PDXFilename;
    if FileExists(WriteFilename)=False then begin
      netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークPDXファイルをダウンロードしています…');
      if (netres=False) and (Main.HTTPSocket.NetworkResult<>Result404Error) then begin // 404Errorは無視
        Main.InfomationVisible('PDXダウンロード失敗');
        Result:=False;
        exit;
      end;
    end;
  end;

{$ifdef mdxwin}
  case DriverMode of
    DriverModeMXDRVm: Result:=MXDRVm.MDXPlay;
    DriverModeMXDRVg: Result:=MXDRVg.MDXPlay;
    else Result:=False;
  end;
{$else}
  case DriverMode of
    DriverModeMXDRVm: Result:=Main.PrgAss.BootMXDRV(Main.gFileInfo);
    DriverModeMXDRVg: Result:=Main.PrgAss.BootMXDRV(Main.gFileInfo);
    else Result:=False;
  end;
{$endif}
end;

function TNetwork.FMPPlay:boolean;
var
  url:string;
  WriteFilename:string;
  netres:boolean;
  MusFilename,PVIFilename,PPZFilename:string;
  SetPCMPath:string;
begin
  url:=ConvPath2URL(CFG.BasePath,Main.gFileInfo.GetFullPath);
  WriteFilename:=Main.gFileInfo.GetNetworkDownloadPath;
  MusFilename:=WriteFilename;
  DeleteFile(WriteFilename);
  netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークFMPファイルをダウンロードしています…');
  if netres=False then begin
    Main.InfomationVisible('FMPダウンロード失敗');
    Result:=False;
    exit;
  end;

{$ifdef mdxwin}
  SetPCMPath:=CFG.FMPPMD_PCMPath;
{$else}
  if Main.gFileInfo.GetNetworkToRealPath=True then begin
    SetPCMPath:=ExtractFilePath(Main.gFileInfo.GetNetworkDownloadPath);
    end else begin
    SetPCMPath:=CFG.FMPPMD_PCMPath;
  end;
{$endif}

  PVIFilename:=FMP.GetPVIFilename(MusFilename);
  if PVIFilename<>'' then PVIFilename:=GetNetworkPCMFilename(PVIFilename);
  if PVIFilename<>'' then begin
    url:=CFG.BasePath+CFG.FMPPMD_PCMURL+PVIFilename;
    WriteFilename:=SetPCMPath+PVIFilename;
    if FileExists(WriteFilename)=False then begin
      netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークPVIファイルをダウンロードしています…');
      if (netres=False) and (Main.HTTPSocket.NetworkResult<>Result404Error) then begin // 404Errorは無視
        Main.InfomationVisible('PVIダウンロード失敗');
        Result:=False;
        exit;
      end;
    end;
  end;

  PPZFilename:=FMP.GetPPZFilename(MusFilename);
  if PPZFilename<>'' then PPZFilename:=GetNetworkPCMFilename(PPZFilename);
  if PPZFilename<>'' then begin
    url:=CFG.BasePath+CFG.FMPPMD_PCMURL+PPZFilename;
    WriteFilename:=SetPCMPath+PPZFilename;
    if FileExists(WriteFilename)=False then begin
      netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークPPZファイルをダウンロードしています…');
      if (netres=False) and (Main.HTTPSocket.NetworkResult<>Result404Error) then begin // 404Errorは無視
        Main.InfomationVisible('PPZダウンロード失敗');
        Result:=False;
        exit;
      end;
    end;
  end;

{$ifdef mdxwin}
  Result:=FMP.FMPPlay;
{$else}
  Result:=Main.PrgAss.BootFMP(Main.gFileInfo);
{$endif}
end;

function TNetwork.PMDPlay:boolean;
var
  url:string;
  WriteFilename:string;
  netres:boolean;
  MusFilename,PPCFilename,PPSFilename,PPZFilename:string;
  SetPCMPath:string;
begin
  url:=ConvPath2URL(CFG.BasePath,Main.gFileInfo.GetFullPath);
  WriteFilename:=Main.gFileInfo.GetNetworkDownloadPath;
  MusFilename:=WriteFilename;
  DeleteFile(WriteFilename);
  netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークPMDファイルをダウンロードしています…');
  if netres=False then begin
    Main.InfomationVisible('PMDダウンロード失敗');
    Result:=False;
    exit;
  end;

{$ifdef mdxwin}
  SetPCMPath:=CFG.FMPPMD_PCMPath;
{$else}
  if Main.gFileInfo.GetNetworkToRealPath=True then begin
    SetPCMPath:=ExtractFilePath(Main.gFileInfo.GetNetworkDownloadPath);
    end else begin
    SetPCMPath:=CFG.FMPPMD_PCMPath;
  end;
{$endif}

  PPCFilename:=PMD.GetPPCFilename(MusFilename);
  if PPCFilename<>'' then PPCFilename:=GetNetworkPCMFilename(PPCFilename);
  if PPCFilename<>'' then begin
    url:=CFG.BasePath+CFG.FMPPMD_PCMURL+PPCFilename;
    WriteFilename:=SetPCMPath+PPCFilename;
    if FileExists(WriteFilename)=False then begin
      netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークPPCファイルをダウンロードしています…');
      if (netres=False) and (Main.HTTPSocket.NetworkResult<>Result404Error) then begin // 404Errorは無視
        Main.InfomationVisible('PPCダウンロード失敗');
        Result:=False;
        exit;
      end;
    end;
  end;

  PPSFilename:=PMD.GetPPSFilename(MusFilename);
  if PPSFilename<>'' then PPSFilename:=GetNetworkPCMFilename(PPSFilename);
  if PPSFilename<>'' then begin
    url:=CFG.BasePath+CFG.FMPPMD_PCMURL+PPSFilename;
    WriteFilename:=SetPCMPath+PPSFilename;
    if FileExists(WriteFilename)=False then begin
      netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークPPSファイルをダウンロードしています…');
      if (netres=False) and (Main.HTTPSocket.NetworkResult<>Result404Error) then begin // 404Errorは無視
        Main.InfomationVisible('PPSダウンロード失敗');
        Result:=False;
        exit;
      end;
    end;
  end;

  PPZFilename:=PMD.GetPPZFilename(MusFilename);
  if PPZFilename<>'' then PPZFilename:=GetNetworkPCMFilename(PPZFilename);
  if PPZFilename<>'' then begin
    url:=CFG.BasePath+CFG.FMPPMD_PCMURL+PPZFilename;
    WriteFilename:=SetPCMPath+PPZFilename;
    if FileExists(WriteFilename)=False then begin
      netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークPPZファイルをダウンロードしています…');
      if (netres=False) and (Main.HTTPSocket.NetworkResult<>Result404Error) then begin // 404Errorは無視
        Main.InfomationVisible('PPZダウンロード失敗');
        Result:=False;
        exit;
      end;
    end;
  end;

{$ifdef mdxwin}
  Result:=PMD.PMDPlay;
{$else}
  Result:=Main.PrgAss.BootPMD(Main.gFileInfo);
{$endif}
end;

function TNetwork.SPCPlay:boolean;
var
  url:string;
  WriteFilename:string;
  netres:boolean;
begin
  url:=ConvPath2URL(CFG.BasePath,Main.gFileInfo.GetFullPath);
  WriteFilename:=Main.gFileInfo.GetNetworkDownloadPath;
  DeleteFile(WriteFilename);
  netres:=GetHTTPDataFileSZip(url,WriteFilename,'ネットワークSPCファイルをダウンロードしています…');
  if netres=False then begin
    Main.InfomationVisible('SPCダウンロード失敗');
    Result:=False;
    exit;
  end;

{$ifdef mdxwin}
  Result:=SPC.SPCPlay;
{$else}
  Result:=Main.PrgAss.BootSPC(Main.gFileInfo);
{$endif}
end;

function TNetwork.GetHTTPDataFile(_url,_WriteFilename,msg:string):boolean;
var
  NeedFile:TNeedFile;
begin
  with NeedFile do begin
    Port:=CFG.Port;
    Host:=CFG.Host;
    URL:=_url;
    UserAgent:=CFG.UserAgent;
    WriteFileSize:=0;
    WriteFileCheckSum:=0;
    WriteFilename:=_WriteFilename;
  end;
  Main.HTTPSocket.SetNeedFile(NeedFile);
  Main.HTTPSocket.GetHTTPFile(msg);

  if Main.HTTPSocket.NetworkResult=ResultSuccess then begin
    result:=True;
    end else begin
    result:=False;
  end;
end;

{
function TNetwork.GetHTTPDataFileZip(_url,_WriteFilename,msg:string):boolean;
var
  zipurl,zipFilename:string;
  ArcFile:TArchiveFile;
  cond:integer;
begin
  zipurl:=_url+'.zip';
  zipFilename:=_WriteFilename+'.zip';
  with Main.HTTPSocket.NeedFile do begin
    Port:=SocketPortNo;
    Host:=CFG.Host;
    URL:=zipurl;
    UserAgent:=CFG.UserAgent;
    WriteFileSize:=0;
    WriteFileCheckSum:=0;
    WriteFilename:=zipFilename;
  end;
  Main.HTTPSocket.GetHTTPFile(msg);

  if Main.HTTPSocket.NeedFile.NetworkResult<>ResultSuccess then begin
    result:=False;
    exit;
  end;

  // CRCチェック
  ArcFile:=TArchiveFile.Create(nil);
  try
    ArcFile.FileName:=zipFilename;
    if (ArcFile.CheckArchive(CHECKARCHIVE_FULLCRC,0) and $7FFF)=0 then begin
      ShowMessage('ダウンロードしたアーカイブのCRCが異常のためカタログが展開できません。');
      Result:=False;
      exit;
    end;
  finally
    ArcFile.Free;
  end;

  // 書庫の解凍
  ArcFile:=TArchiveFile.Create(nil);
  try
    ArcFile.FileName:=zipFilename;

    ArcFile.Options.x:=1; // ディレクトリ展開
    ArcFile.OutputSize:=0; // 出力バッファサイズ

    ArcFile.Options.n:=1;
    ArcFile.OnProgress:=nil;

    cond:=ArcFile.UnpackFiles(0,nil,ExtractFilePath(zipFilename),[nil]);
    if cond<>0 then begin
      ShowMessage('解凍に失敗しました。空き容量が原因の可能性があります。Result:'+inttohex(cond,4));
      Result:=False;
      exit;
    end;
  finally
    ArcFile.Free;
  end;

  DeleteFile(zipFilename);
  Result:=True;
end;
}

function TNetwork.GetHTTPDataFileSZip(_url,_WriteFilename,msg:string):boolean;
var
  res:integer;
  NeedFile:TNeedFile;
begin
  with NeedFile do begin
    Port:=CFG.Port;
    Host:=CFG.Host;
    if MainINI.MDXOnlineBufferSize<>0 then begin
      BufferSize:=MainINI.MDXOnlineBufferSize;
      end else begin
      BufferSize:=256;
    end;
    URL:=_url+'.szip';
    UserAgent:=CFG.UserAgent;
    WriteFileSize:=0;
    WriteFileCheckSum:=0;
    WriteFilename:='';
  end;
  Main.HTTPSocket.SetNeedFile(NeedFile);
  Main.HTTPSocket.GetHTTPFile(msg);

  if Main.HTTPSocket.NetworkResult<>ResultSuccess then begin
    result:=False;
    exit;
  end;

  res:=SZipDecompress(Main.HTTPSocket.Buffer,Main.HTTPSocket.BufferCount,_WriteFilename);
  DeleteFile(NeedFile.WriteFilename);
  if res<>SZipSuccess then begin
    ShowMessage('MDXOnline','解凍に失敗しました。Result:'+inttostr(res));
    Result:=False;
    exit;
  end;

  Result:=True;
end;

procedure TNetwork.LoadPCMFileList;
var
  fname:string;
  rfb:TReadFileBuf;
  cnt,Count:integer;
begin
  MXDRVPDXFileList.Clear;
  FMPMDPCMFileList.Clear;

  fname:=CFG.PCMFileListFilename;
  if FileExists(fname)=False then exit;

  rfb:=TReadFileBuf.Create;
  rfb.Init(fname);
  rfb.LoadFile;
  Count:=rfb.GetWord;
  for cnt:=0 to Count-1 do begin
    case rfb.GetByte of
      0: MXDRVPDXFileList.Add(rfb.GetMString);
      1: FMPMDPCMFileList.Add(rfb.GetMString);
    end;
  end;
  rfb.Free;
end;

function TNetwork.GetNetworkPDXFilename(PDXFilename:string):string;
var
  cnt:integer;
  ext:string;
  fname,fnames,fnamef,fname8:string;
begin
  Result:='';

  ext:='.pdx';
  fname:=thChangeFileExt(AnsiLowerCase(PDXFilename),'');
  fnamef:=fname+ext;
  fname8:=copy(fname,1,8)+ext;

  with MXDRVPDXFileList do begin
    for cnt:=0 to Count-1 do begin
      fnames:=AnsiLowerCase(Strings[cnt]);
      if (fnames=fnamef) or (fnames=fname8) then begin
        Result:=Strings[cnt];
        exit;
      end;
    end;
  end;
end;

function TNetwork.GetNetworkPCMFilename(PCMFilename:string):string;
var
  cnt:integer;
  fnames,fnamef:string;
begin
  Result:='';

  fnamef:=AnsiLowerCase(PCMFilename);

  with FMPMDPCMFileList do begin
    for cnt:=0 to Count-1 do begin
      fnames:=AnsiLowerCase(Strings[cnt]);
      if fnames=fnamef then begin
        Result:=Strings[cnt];
        exit;
      end;
    end;
  end;
end;

end.
