⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pathfn.cpp

📁 我把unrar的代码整理成vc工程了
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    RemoveNameFromPath(Path);  }  return(true);#else  return(false);#endif}#endif#ifndef SFX_MODULEvoid GetConfigName(const char *Name,char *FullName,bool CheckExist){  *FullName=0;  for (int I=0;EnumConfigPaths(FullName,I);I++)  {    AddEndSlash(FullName);    strcat(FullName,Name);    if (!CheckExist || WildFileExist(FullName))      break;  }}#endif// Returns a pointer to rightmost digit of volume number.char* GetVolNumPart(char *ArcName){  // Pointing to last name character.  char *ChPtr=ArcName+strlen(ArcName)-1;  // Skipping the archive extension.  while (!isdigit(*ChPtr) && ChPtr>ArcName)    ChPtr--;  // Skipping the numeric part of name.  char *NumPtr=ChPtr;  while (isdigit(*NumPtr) && NumPtr>ArcName)    NumPtr--;  // Searching for first numeric part in names like name.part##of##.rar.  // Stop search on the first dot.  while (NumPtr>ArcName && *NumPtr!='.')  {    if (isdigit(*NumPtr))    {      // Validate the first numeric part only if it has a dot somwhere       // before it.      char *Dot=strchrd(PointToName(ArcName),'.');      if (Dot!=NULL && Dot<NumPtr)        ChPtr=NumPtr;      break;    }    NumPtr--;  }  return(ChPtr);}void NextVolumeName(char *ArcName,wchar *ArcNameW,uint MaxLength,bool OldNumbering){  char *ChPtr;  if ((ChPtr=GetExt(ArcName))==NULL)  {    strcat(ArcName,".rar");    ChPtr=GetExt(ArcName);  }  else    if (ChPtr[1]==0 || stricomp(ChPtr+1,"exe")==0 || stricomp(ChPtr+1,"sfx")==0)      strcpy(ChPtr+1,"rar");  if (!OldNumbering)  {    ChPtr=GetVolNumPart(ArcName);    while ((++(*ChPtr))=='9'+1)    {      *ChPtr='0';      ChPtr--;      if (ChPtr<ArcName || !isdigit(*ChPtr))      {        for (char *EndPtr=ArcName+strlen(ArcName);EndPtr!=ChPtr;EndPtr--)          *(EndPtr+1)=*EndPtr;        *(ChPtr+1)='1';        break;      }    }  }  else    if (!isdigit(*(ChPtr+2)) || !isdigit(*(ChPtr+3)))      strcpy(ChPtr+2,"00");    else    {      ChPtr+=3;      while ((++(*ChPtr))=='9'+1)        if (*(ChPtr-1)=='.')        {          *ChPtr='A';          break;        }        else        {          *ChPtr='0';          ChPtr--;        }    }  if (ArcNameW!=NULL && *ArcNameW!=0)  {    // Copy incremented trailing low ASCII volume name part to Unicode name.    // It is simpler than implementing Unicode version of entire function.    char *NumPtr=GetVolNumPart(ArcName);    // moving to first digit in volume number    while (NumPtr>ArcName && isdigit(*NumPtr) && isdigit(*(NumPtr-1)))      NumPtr--;    // also copy the first character before volume number,    // because it can be changed when going from .r99 to .s00    if (NumPtr>ArcName)      NumPtr--;    int CharsToCopy=strlen(ArcName)-(NumPtr-ArcName);    int DestPos=strlenw(ArcNameW)-CharsToCopy;    if (DestPos>=0)    {      CharToWide(NumPtr,ArcNameW+DestPos,MaxLength-DestPos-1);      ArcNameW[MaxLength-1]=0;    }  }}bool IsNameUsable(const char *Name){#ifndef _UNIX  if (Name[0] && Name[1] && strchr(Name+2,':')!=NULL)    return(false);  for (const char *s=Name;*s!=0;s=charnext(s))  {    if (*s<32)      return(false);    if (*s==' ' && IsPathDiv(s[1]))      return(false);  }#endif  return(*Name!=0 && strpbrk(Name,"?*<>|\"")==NULL);}void MakeNameUsable(char *Name,bool Extended){  for (char *s=Name;*s!=0;s=charnext(s))  {    if (strchr(Extended ? "?*<>|\"":"?*",*s)!=NULL || Extended && *s<32)      *s='_';#ifdef _EMX    if (*s=='=')      *s='_';#endif#ifndef _UNIX    if (s-Name>1 && *s==':')      *s='_';    if (*s==' ' && IsPathDiv(s[1]))      *s='_';#endif  }}char* UnixSlashToDos(char *SrcName,char *DestName,uint MaxLength){  if (DestName!=NULL && DestName!=SrcName)    if (strlen(SrcName)>=MaxLength)    {      *DestName=0;      return(DestName);    }    else      strcpy(DestName,SrcName);  for (char *s=SrcName;*s!=0;s=charnext(s))  {    if (*s=='/')      if (DestName==NULL)        *s='\\';      else        DestName[s-SrcName]='\\';  }  return(DestName==NULL ? SrcName:DestName);}char* DosSlashToUnix(char *SrcName,char *DestName,uint MaxLength){  if (DestName!=NULL && DestName!=SrcName)    if (strlen(SrcName)>=MaxLength)    {      *DestName=0;      return(DestName);    }    else      strcpy(DestName,SrcName);  for (char *s=SrcName;*s!=0;s=charnext(s))  {    if (*s=='\\')      if (DestName==NULL)        *s='/';      else        DestName[s-SrcName]='/';  }  return(DestName==NULL ? SrcName:DestName);}wchar* UnixSlashToDos(wchar *SrcName,wchar *DestName,uint MaxLength){  if (DestName!=NULL && DestName!=SrcName)    if (strlenw(SrcName)>=MaxLength)    {      *DestName=0;      return(DestName);    }    else      strcpyw(DestName,SrcName);  for (wchar *s=SrcName;*s!=0;s++)  {    if (*s=='/')      if (DestName==NULL)        *s='\\';      else        DestName[s-SrcName]='\\';  }  return(DestName==NULL ? SrcName:DestName);}bool IsFullPath(const char *Path){  char PathOnly[NM];  GetFilePath(Path,PathOnly,ASIZE(PathOnly));  if (IsWildcard(PathOnly,NULL))    return(true);#if defined(_WIN_32) || defined(_EMX)  return(Path[0]=='\\' && Path[1]=='\\' ||         IsDiskLetter(Path) && IsPathDiv(Path[2]));#else  return(IsPathDiv(Path[0]));#endif}bool IsFullPath(const wchar *Path){  wchar PathOnly[NM];  GetFilePath(Path,PathOnly,ASIZE(PathOnly));  if (IsWildcard(NULL,PathOnly))    return(true);#if defined(_WIN_32) || defined(_EMX)  return(Path[0]=='\\' && Path[1]=='\\' ||         IsDiskLetter(Path) && IsPathDiv(Path[2]));#else  return(IsPathDiv(Path[0]));#endif}bool IsDiskLetter(const char *Path){  char Letter=etoupper(Path[0]);  return(Letter>='A' && Letter<='Z' && IsDriveDiv(Path[1]));}bool IsDiskLetter(const wchar *Path){  int Letter=etoupper(Path[0]);  return(Letter>='A' && Letter<='Z' && IsDriveDiv(Path[1]));}void GetPathRoot(const char *Path,char *Root){  *Root=0;  if (IsDiskLetter(Path))    sprintf(Root,"%c:\\",*Path);  else    if (Path[0]=='\\' && Path[1]=='\\')    {      const char *Slash=strchr(Path+2,'\\');      if (Slash!=NULL)      {        size_t Length;        if ((Slash=strchr(Slash+1,'\\'))!=NULL)          Length=Slash-Path+1;        else          Length=strlen(Path);        strncpy(Root,Path,Length);        Root[Length]=0;      }    }}int ParseVersionFileName(char *Name,wchar *NameW,bool Truncate){  int Version=0;  char *VerText=strrchrd(Name,';');  if (VerText!=NULL)  {    Version=atoi(VerText+1);    if (Truncate)      *VerText=0;  }  if (NameW!=NULL)  {    wchar *VerTextW=strrchrw(NameW,';');    if (VerTextW!=NULL)    {      if (Version==0)        Version=atoiw(VerTextW+1);      if (Truncate)        *VerTextW=0;    }  }  return(Version);}#ifndef SFX_MODULEchar* VolNameToFirstName(const char *VolName,char *FirstName,bool NewNumbering){  if (FirstName!=VolName)    strcpy(FirstName,VolName);  char *VolNumStart=FirstName;  if (NewNumbering)  {    int N='1';    for (char *ChPtr=GetVolNumPart(FirstName);ChPtr>FirstName;ChPtr--)      if (isdigit(*ChPtr))      {        *ChPtr=N;        N='0';      }      else        if (N=='0')        {          VolNumStart=ChPtr+1;          break;        }  }  else  {    SetExt(FirstName,"rar");    VolNumStart=GetExt(FirstName);  }  if (!FileExist(FirstName))  {    char Mask[NM];    strcpy(Mask,FirstName);    SetExt(Mask,"*");    FindFile Find;    Find.SetMask(Mask);    struct FindData FD;    while (Find.Next(&FD))    {      Archive Arc;      if (Arc.Open(FD.Name,FD.NameW) && Arc.IsArchive(true) && !Arc.NotFirstVolume)      {        strcpy(FirstName,FD.Name);        break;      }    }  }  return(VolNumStart);}#endifwchar* GetWideName(const char *Name,const wchar *NameW,wchar *DestW){  if (NameW!=NULL && *NameW!=0)  {    if (DestW!=NameW)      strcpyw(DestW,NameW);  }  else    CharToWide(Name,DestW);  return(DestW);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -