Exemplo n.º 1
0
int CdromDriverLinux::OpenDrive(memptr device)
{
	int drive;

	drive = GetDrive(device);
	drive = DriveFromLetter(drive);
	
	/* Drive exist ? */
	if (drive < 0 || drive >= CD_MAX_DRIVES || (drives_mask & (1<<drive)) == 0 ||
		DeviceName(drive = bx_options.nfcdroms[drive].physdevtohostdev) == NULL)
	{
		D(bug(NFCD_NAME " physical device %c does not exist", GetDrive(device)));
		return TOS_EUNDEV;
	}

	/* Drive opened ? */
	if (cddrives[drive].handle>=0) {
		return drive;
	}

	/* Open drive */
	cddrives[drive].handle=open(DeviceName(drive), O_RDONLY|O_EXCL|O_NONBLOCK, 0);
	if (cddrives[drive].handle<0) {
		cddrives[drive].handle=-1;
		int errorcode = errnoHost2Mint(errno, TOS_EFILNF);
		D(bug(NFCD_NAME " error opening drive %s: %s", DeviceName(drive), strerror(errno)));
		return errorcode;
	}

	return drive;
}
Exemplo n.º 2
0
void UnitDriveTests()
{
	struct {
		LPCWSTR asPath, asResult;
	} Tests[] = {
		{L"C:", L"C:"},
		{L"C:\\Dir1\\Dir2\\File.txt", L"C:"},
		{L"\\\\Server\\Share", L"\\\\Server\\Share"},
		{L"\\\\Server\\Share\\Dir1\\Dir2\\File.txt", L"\\\\Server\\Share"},
		{L"\\\\?\\UNC\\Server\\Share", L"\\\\?\\UNC\\Server\\Share"},
		{L"\\\\?\\UNC\\Server\\Share\\Dir1\\Dir2\\File.txt", L"\\\\?\\UNC\\Server\\Share"},
		{L"\\\\?\\C:", L"\\\\?\\C:"},
		{L"\\\\?\\C:\\Dir1\\Dir2\\File.txt", L"\\\\?\\C:"},
		{NULL}
	};
	bool bCheck;
	wchar_t szDrive[MAX_PATH];
	for (size_t i = 0; Tests[i].asPath; i++)
	{
		wmemset(szDrive, L'z', countof(szDrive));
		bCheck = (wcscmp(GetDrive(Tests[i].asPath, szDrive, countof(szDrive)), Tests[i].asResult) == 0);
		_ASSERTE(bCheck);
	}
	bCheck = true;
}
Exemplo n.º 3
0
void DOS_FCB::GetName(char * fillname) {
	fillname[0]=GetDrive()+'A';
	fillname[1]=':';
	MEM_BlockRead(pt+offsetof(sFCB,filename),&fillname[2],8);
	fillname[10]='.';
	MEM_BlockRead(pt+offsetof(sFCB,ext),&fillname[11],3);
	fillname[14]=0;
}
Exemplo n.º 4
0
void SetConEmuWorkEnvVar(HMODULE hConEmuCD)
{
	wchar_t szPath[MAX_PATH*2] = L"";
	GetCurrentDirectory(countof(szPath), szPath);
	SetEnvironmentVariable(ENV_CONEMUWORKDIR_VAR_W, szPath);

	wchar_t szDrive[MAX_PATH];
	SetEnvironmentVariable(ENV_CONEMUWORKDRIVE_VAR_W, GetDrive(szPath, szDrive, countof(szDrive)));
	GetModuleFileName(hConEmuCD, szPath, countof(szPath));
	SetEnvironmentVariable(ENV_CONEMUDRIVE_VAR_W, GetDrive(szPath, szDrive, countof(szDrive)));

	// Same as gpConEmu->ms_ConEmuBuild
	wchar_t szVer4[8] = L""; lstrcpyn(szVer4, WSTRING(MVV_4a), countof(szVer4));
	msprintf(szDrive, countof(szDrive), L"%02u%02u%02u%s%s",
		(MVV_1%100), MVV_2, MVV_3, szVer4[0]&&szVer4[1]?L"-":L"", szVer4);
	SetEnvironmentVariable(ENV_CONEMU_BUILD_W, szDrive);
}
Exemplo n.º 5
0
acoral_32 acoral_umount(const char *target)
{
	acoral_u32 ret;
	ret=acoral_mutex_pend(fs_mutex,0);
	if(ret!=MUTEX_SUCCED)
		return -1;
	RemoveFileDriver(GetDrive(target));
	acoral_mutex_post(fs_mutex);
	return 0;
}
Exemplo n.º 6
0
void DOS_FCB::FileOpen(Bit8u _fhandle) {
	sSave(sFCB,drive,GetDrive()+1);
	sSave(sFCB,file_handle,_fhandle);
	sSave(sFCB,cur_block,0);
	sSave(sFCB,rec_size,128);
//	sSave(sFCB,rndm,0); // breaks Jewels of darkness. 
	Bit32u size = 0;
	Files[_fhandle]->Seek(&size,DOS_SEEK_END);
	sSave(sFCB,filesize,size);
	size = 0;
	Files[_fhandle]->Seek(&size,DOS_SEEK_SET);
	sSave(sFCB,time,Files[_fhandle]->time);
	sSave(sFCB,date,Files[_fhandle]->date);
}
Exemplo n.º 7
0
bool Pathname::FullToRelative(const Pathname &relativeto)
{
  if (relativeto.IsNull() || IsNull()) return false;
  bool h1= HasDrive();
  bool h2= relativeto.HasDrive();
  if (h1 != h2) return false;         //rozdilny zpusob adresace - nelze vytvorit relatvni cestu
  if (h1== true && h2== true && toupper(GetDrive()) != toupper(relativeto.GetDrive()))
    return false;       //ruzne disky, nelze vytvorit relativni cestu
  if (strncmp(_path,"\\\\",2) == 0) //sitova cesta
  {
    int slsh = 0;           //citac lomitek
    const char *a = _path;
    const char *b = relativeto._path;
    while (toupper(*a) == toupper(*b) && *a && slsh<3)  //zacatek sitove cesty musi byt stejny
    {
      if (*a =='\\') slsh++;
      a++;b++;
    }
    if (slsh != 3) return false;      //pokud neni stejny, nelze vytvorit relativni cestu
  }
  int sublevel = 0;
  const char *ps1= _path;
  const char *ps2= relativeto._path;
  if (h1) 
  {ps1 += 2;ps2 += 2;}
  const char *sls = ps2;
  while (toupper(*ps1) == toupper(*ps2) && *ps1) 
  {
    if (*ps2=='\\') sls = ps2+1;
    ps1++;ps2++;
  }
  ps1 -= ps2-sls;
  if (sls)
  {    
    while (sls = strchr(sls,'\\'))
    {
      sls++;
      sublevel++;
    }
  }
  char *buff = (char *)alloca((sublevel*3+strlen(ps1)+1)*sizeof(*buff));
  char *pos = buff;
  for (int i = 0;i<sublevel;i++) 
  {strcpy(pos,"..\\");pos += 3;}
  strcpy(pos,ps1);
  SetDrive(0);
  SetDirectory(buff);
  return true;
}
Exemplo n.º 8
0
    SlotImpl *
    Factory::GetSlot(int changer,int number)
    {
        if ( number < 0 ) {
            return GetDrive(changer,number);
        }

        boost::lock_guard<boost::mutex> lock(mutex_);

        SlotMap::iterator i = slots_.find(Key(changer,number));
        if ( slots_.end() == i ) {
            return NULL;
        }
        return &i->second;
    }
VOID CIoSupport::GetXbePath(char* szDest)
{
#ifdef _XBOX
  //Function to get the XBE Path like:
  //E:\DevKit\xbplayer\xbplayer.xbe

  char szTemp[MAX_PATH];
  char cDriveLetter = 0;

  strncpy(szTemp, XeImageFileName->Buffer + 8, XeImageFileName->Length - 8);
  szTemp[20] = 0;
  GetDrive(szTemp, &cDriveLetter);

  strncpy(szTemp, XeImageFileName->Buffer + 29, XeImageFileName->Length - 29);
  szTemp[XeImageFileName->Length - 29] = 0;

  sprintf(szDest, "%c:\\%s", cDriveLetter, szTemp);

#elif WIN32
  wchar_t szAppPathW[MAX_PATH] = L"";
  ::GetModuleFileNameW(0, szAppPathW, sizeof(szAppPathW) - 1);
  CStdStringW strPathW = szAppPathW;
  CStdString strPath;
  g_charsetConverter.wToUTF8(strPathW,strPath);
  strncpy(szDest,strPath.c_str(),strPath.length()+1);
#elif __APPLE__
  int      result = -1;
  char     given_path[2*MAXPATHLEN];
  uint32_t path_size = 2*MAXPATHLEN;

  result = _NSGetExecutablePath(given_path, &path_size);
  if (result == 0)
    realpath(given_path, szDest);
#else
  /* Get our PID and build the name of the link in /proc */
  pid_t pid = getpid();
  char linkname[64]; /* /proc/<pid>/exe */
  snprintf(linkname, sizeof(linkname), "/proc/%i/exe", pid);

  /* Now read the symbolic link */
  char buf[1024];
  int ret = readlink(linkname, buf, 1024);
  buf[ret] = 0;
	
  strcpy(szDest, buf);
#endif
}
Exemplo n.º 10
0
acoral_32 acoral_mount(acoral_char *source,const char *target,
					   const acoral_char *filesystemtype,acoral_u32 mountflags,
					   const void *data)
{
	acoral_u32 ret;
	acoral_32 fs_ret;
	ret=acoral_mutex_pend(fs_mutex,0);
	if(ret!=MUTEX_SUCCED)
		return -1;
	fs_ret=AddFileDriver(FsCommand,source,GetDrive(target));
	if(fs_ret==-1)
	{
		acoral_mutex_post(fs_mutex);
		return -1;
	}
	acoral_mutex_post(fs_mutex);
	return 0;
}
Exemplo n.º 11
0
/*********************************************************************************************************
** 函数名称: RemoveDir
** 功能描述: 删除目录
**
** 输 入: Path:路径名
**
** 输 出: RETURN_OK:成功
**        其它参考fat.h中关于返回值的说明
** 全局变量: 无
** 调用模块: strupr,DelFDT
********************************************************************************************************/
        acoral_u8 RemoveDir(acoral_char *Path)
{
    acoral_u32 ClusIndex, ClusIndex1;
    acoral_u8 Drive, Rt;
    acoral_char DirName[12];
    FDT temp;
    
    strupr(Path);                       /* 变为大写 */

    ClusIndex = _GetFDTInfo(DirName, Path);
    if (ClusIndex == BAD_CLUS)
    {
        return PATH_NOT_FIND;
    }

    Drive = GetDrive(Path);
    
    /* 获取FDT其信息 */
    Rt = FindFDTInfo(&temp, Drive, ClusIndex, DirName);
    if (Rt == RETURN_OK)
    {
        /* 是否是目录 */
        if ((temp.Attr & ATTR_DIRECTORY) != 0)
        {
            /* 是 */
            ClusIndex1 = temp.FstClusLO + ((acoral_u32)(temp.FstClusHI) << 16);
            /* 是否是空目录 */
            Rt = DirIsEmpty(Drive, ClusIndex1);
            if (Rt == DIR_EMPTY)
            {
                /* 是,删除 */
                FATDelClusChain(Drive, ClusIndex1);
                Rt = DelFDT(Drive, ClusIndex, DirName);
            }
        }
        else
        {
            return PATH_NOT_FIND;
        }
    }
    return Rt;
}
Exemplo n.º 12
0
/*********************************************************************************************************
** 函数名称: ChangeDir
** 功能描述: 改变当前目录
**
** 输 入: Path:路径名
**
** 输 出: RETURN_OK:成功
**        其它参考fat.h中关于返回值的说明
** 全局变量: 无
** 调用模块: GetDirClusIndex,GetDiskInfo
********************************************************************************************************/
        acoral_u8 ChangeDir(acoral_char *Path)
{
    acoral_u32 ClusIndex;
    acoral_u8 Rt, Drive;
    Disk_Info *Disk;

    Rt = PATH_NOT_FIND;
    ClusIndex = GetDirClusIndex(Path);
    if (ClusIndex != BAD_CLUS)
    {
        Drive = GetDrive(Path);
        Disk = GetDiskInfo(Drive);
        Rt = NOT_FIND_DISK;
        if (Disk != NULL)
        {
            Rt = RETURN_OK;
            Disk->PathClusIndex = ClusIndex;
        }
    }
    return Rt;
}
Exemplo n.º 13
0
bool Pathname::RelativeToFull(const Pathname &ref)
{
  if (ref.IsNull() || IsNull()) return false;  
  const char *beg;
  if (HasDrive())
    if (toupper(GetDrive()) != toupper(ref.GetDrive())) return false;
    else beg = _path+2;
  else beg = _path;
  const char *end = strchr(ref._path,0);  
  if (beg[0] =='\\')
  {
    int np;
    if (ref.HasDrive()) end = ref._path+2;
    else  if (np = ref.IsNetworkPath()) end = ref._path+np;
    else end = ref._path;
  }
  else while (strncmp(beg,"..\\",3) == 0 || strncmp(beg,".\\",2) == 0)
  {
    if (beg[1] =='.')
    {
      if (end>ref._path)
      {
        end--;
        while (end>ref._path && end[-1]!='\\') end--;
      }      
      beg += 3;
    }
    else 
      beg += 2;
  }
  int partln = end-ref._path;
  char *buff = (char *)alloca((partln+strlen(beg)+1)*sizeof(*buff));
  memcpy(buff,ref._path,partln);
  strcpy(buff+partln,beg);
  SetDrive(0);
  SetDirectory(buff);
  return true;
}
Exemplo n.º 14
0
DualErr 
PGPdisk::Write(
	PGPUInt8			*buf, 
	PGPUInt64			pos, 
	PGPUInt32			nBytes, 
	GenericCallbackInfo	*upInfo)
{
	DualErr derr;

	pgpAssertAddrValid(buf, PGPUInt8);
	pgpAssert(Mounted());

	DebugOut("PGPdisk: Writing PGPdisk %u at pos %u nBlocks %u", GetDrive(), 
		(PGPUInt32) (pos/kDefaultBlockSize), 
		(PGPUInt32) (nBytes/kDefaultBlockSize));

	if (upInfo)
		WriteAsync(buf, pos, nBytes, upInfo);
	else
		derr = WriteSync(buf, pos, nBytes);

	return derr;
}
Exemplo n.º 15
0
CString CGetEnvPath::GetEnvVariable(LPCTSTR pszName)
{
    CString strResult;
	WCHAR wcsTemp[MAX_PATH] = {0}; 
    
    TCHAR szBuffer[MAX_PATH] = { 0 };
    TCHAR szLongPathBuffer[MAX_PATH] = { 0 };

    if ( CString("systemdrive").CompareNoCase(pszName) == 0 )
    {
        //UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);
        //strResult = GetDrive(_T(""));
        UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);

        if (uResult > 3 && szBuffer[1] == TEXT(':') && szBuffer[2] == TEXT('\\'))
        {
            szBuffer[2] = TEXT('\0');
            strResult = szBuffer;
            goto Exit0;         
        }
    }
    else if ( CString("program").CompareNoCase(pszName) == 0 )
    {
        //UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);
        //strResult = GetDrive(_T(""));
        UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);

        if (uResult > 3 && szBuffer[1] == TEXT(':') && szBuffer[2] == TEXT('\\'))
        {
            szBuffer[3] = TEXT('\0');
            strResult = szBuffer;
            strResult += L"program files";
            goto Exit0;         
        }
    }
    else if ( CString("boot").CompareNoCase(pszName) == 0 )
    {
        //UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);
        //strResult = GetDrive(_T(""));
        UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);

        if (uResult > 3 && szBuffer[1] == TEXT(':') && szBuffer[2] == TEXT('\\'))
        {
            szBuffer[3] = TEXT('\0');
            strResult = szBuffer;
            strResult += L"boot";
            goto Exit0;         
        }
    }
    else if ( CString("recovery").CompareNoCase(pszName) == 0 )
    {
        //UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);
        //strResult = GetDrive(_T(""));
        UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);

        if (uResult > 3 && szBuffer[1] == TEXT(':') && szBuffer[2] == TEXT('\\'))
        {
            szBuffer[3] = TEXT('\0');
            strResult = szBuffer;
            strResult += L"recovery";
            goto Exit0;         
        }
    }
    else if ( CString("systemroot").CompareNoCase(pszName) == 0 )
    {
       
        UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);

        if (uResult > 0)
        {
            strResult = szBuffer;
            goto Exit0;         
        }
    }
    else if(CString("windir").CompareNoCase(pszName) == 0)
    {
        UINT uResult = GetWindowsDirectory(szBuffer, MAX_PATH);

        if(szBuffer[wcslen(szBuffer)-1] == _T('\\'))
            szBuffer[wcslen(szBuffer)-1] = _T('\0');

        strResult = szBuffer;
        goto Exit0;
    }
    else if ( CString("systemrecycled").CompareNoCase(pszName) == 0 )
    {
        SYSTEM_VERSION     m_eSysVer;
        KAEGetSystemVersion(&m_eSysVer);
        CString StrSuffix;
        if(m_eSysVer == enumSystem_Win_7)
        {
            StrSuffix = _T("\\$RECYCLE.BIN");
        }
        else
            StrSuffix = _T("\\Recycled");
        strResult = GetDrive(StrSuffix);

        goto Exit0;
    }
	else if ( CString("minidump").CompareNoCase(pszName) == 0 )
	{
		DWORD len = sizeof(szLongPathBuffer);
		GetRegistryValue(HKEY_LOCAL_MACHINE,
			L"SYSTEM\\CurrentControlSet\\Control\\CrashControl",
			L"MinidumpDir",
			NULL,
			(LPBYTE)szLongPathBuffer,
			&len
			);
		if(wcslen(szLongPathBuffer) == 0)
			strResult = L"%minidump%";
		else
		{
			int nFirstPos  = 0; 
			int nSecondPos = 0;
			BOOL bFind = FALSE;
			bFind = FindEnvironmentPos(szLongPathBuffer, nFirstPos, nSecondPos);
			if(bFind)
			{
				CString strLeft       ;
				CString strRight      ;
				CString strEnvName    ;
				CString strEnvVariable;
				
				strResult = szLongPathBuffer;
				strLeft    = strResult.Left(nFirstPos);
				strRight   = strResult.Mid (nSecondPos + 1);
				strEnvName = strResult.Mid(nFirstPos + 1, nSecondPos - nFirstPos - 1);
				TCHAR szTempBuf[MAX_PATH];
				DWORD dwResult = GetEnvironmentVariable(strEnvName.GetBuffer(), szTempBuf, MAX_PATH);
				if (dwResult > 0)
					strEnvVariable = szTempBuf;

				strResult = CombinationPath(strLeft, strEnvVariable, strRight);

			}
			else
				strResult = szLongPathBuffer;

			goto Exit0;

		}
	}
	else if ( CString("memdump").CompareNoCase(pszName) == 0 )
	{
		DWORD len = sizeof(szLongPathBuffer);
		GetRegistryValue(HKEY_LOCAL_MACHINE,
			L"SYSTEM\\CurrentControlSet\\Control\\CrashControl",
			L"DumpFile",
			NULL,
			(LPBYTE)szLongPathBuffer,
			&len
			);
		if(wcslen(szLongPathBuffer) == 0)
			strResult = L"%memdump%";
		else
		{
			int nFirstPos  = 0; 
			int nSecondPos = 0;
			BOOL bFind = FALSE;
			bFind = FindEnvironmentPos(szLongPathBuffer, nFirstPos, nSecondPos);
			if(bFind)
			{
				CString strLeft       ;
				CString strRight      ;
				CString strEnvName    ;
				CString strEnvVariable;

				strResult = szLongPathBuffer;
				strLeft    = strResult.Left(nFirstPos);
				strRight   = strResult.Mid (nSecondPos + 1);
				strEnvName = strResult.Mid(nFirstPos + 1, nSecondPos - nFirstPos - 1);
				TCHAR szTempBuf[MAX_PATH];
				DWORD dwResult = GetEnvironmentVariable(strEnvName.GetBuffer(), szTempBuf, MAX_PATH);
				if (dwResult > 0)
					strEnvVariable = szTempBuf;

				strResult = CombinationPath(strLeft, strEnvVariable, L"");
				strResult += strRight;
			}
			else
				strResult = szLongPathBuffer;
			if (GetFileAttributes(strResult.GetBuffer()) != FILE_ATTRIBUTE_DIRECTORY)
			{
				WCHAR szTempBuffer[MAX_PATH] = {0};
				wcscpy_s(szTempBuffer, MAX_PATH - 1, strResult.GetBuffer());
				::PathRemoveFileSpec(szTempBuffer);
				strResult = szTempBuffer;
			}

			goto Exit0;

		}
	}
	else if (CString("archivefiles").CompareNoCase(pszName) == 0)
	{
		DWORD len = sizeof(szLongPathBuffer);
		GetRegistryValue(HKEY_LOCAL_MACHINE,
			L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VolumeCaches\\Windows Error Reporting Archive Files",
			L"Folder",
			NULL,
			(LPBYTE)szLongPathBuffer,
			&len
			);
		if (wcslen(szLongPathBuffer) == 0)
		{
			strResult = L"%archivefiles%";
		}
		else
		{
			int nFirstPos  = 0; 
			int nSecondPos = 0;
			BOOL bFind = FALSE;
			bFind = FindEnvironmentPos(szLongPathBuffer, nFirstPos, nSecondPos);
			if(bFind)
			{
				CString strLeft       ;
				CString strRight      ;
				CString strEnvName    ;
				CString strEnvVariable;

				strResult = szLongPathBuffer;
				strLeft    = strResult.Left(nFirstPos);
				strRight   = strResult.Mid (nSecondPos + 1);
				strEnvName = strResult.Mid(nFirstPos + 1, nSecondPos - nFirstPos - 1);
				TCHAR szTempBuf[MAX_PATH];
				DWORD dwResult = GetEnvironmentVariable(strEnvName.GetBuffer(), szTempBuf, MAX_PATH);
				if (dwResult > 0)
					strEnvVariable = szTempBuf;

				strResult = CombinationPath(strLeft, strEnvVariable, L"");
				strResult += strRight;
			}
			else
			{
				strResult = szLongPathBuffer;
			}
			goto Exit0;

		}
	}
	else if (CString("queuefiles").CompareNoCase(pszName) == 0)
	{
		DWORD len = sizeof(szLongPathBuffer);
		GetRegistryValue(HKEY_LOCAL_MACHINE,
			L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VolumeCaches\\Windows Error Reporting Queue Files",
			L"Folder",
			NULL,
			(LPBYTE)szLongPathBuffer,
			&len
			);
		if (wcslen(szLongPathBuffer) == 0)
		{
			strResult = L"%queuefiles%";
		}
		else
		{
			int nFirstPos  = 0; 
			int nSecondPos = 0;
			BOOL bFind = FALSE;
			bFind = FindEnvironmentPos(szLongPathBuffer, nFirstPos, nSecondPos);
			if(bFind)
			{
				CString strLeft       ;
				CString strRight      ;
				CString strEnvName    ;
				CString strEnvVariable;

				strResult = szLongPathBuffer;
				strLeft    = strResult.Left(nFirstPos);
				strRight   = strResult.Mid (nSecondPos + 1);
				strEnvName = strResult.Mid(nFirstPos + 1, nSecondPos - nFirstPos - 1);
				TCHAR szTempBuf[MAX_PATH];
				DWORD dwResult = GetEnvironmentVariable(strEnvName.GetBuffer(), szTempBuf, MAX_PATH);
				if (dwResult > 0)
					strEnvVariable = szTempBuf;

				strResult = CombinationPath(strLeft, strEnvVariable, L"");
				strResult += strRight;
			}
			else
			{
				strResult = szLongPathBuffer;
			}
			goto Exit0;

		}
	}
	else if (CString("systemarchivefiles").CompareNoCase(pszName) == 0)
	{
		DWORD len = sizeof(szLongPathBuffer);
		GetRegistryValue(HKEY_LOCAL_MACHINE,
			L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VolumeCaches\\Windows Error Reporting System Archive Files",
			L"Folder",
			NULL,
			(LPBYTE)szLongPathBuffer,
			&len
			);
		if (wcslen(szLongPathBuffer) == 0)
		{
			strResult = L"%systemarchivefiles%";
		}
		else
		{
			int nFirstPos  = 0; 
			int nSecondPos = 0;
			BOOL bFind = FALSE;
			bFind = FindEnvironmentPos(szLongPathBuffer, nFirstPos, nSecondPos);
			if(bFind)
			{
				CString strLeft       ;
				CString strRight      ;
				CString strEnvName    ;
				CString strEnvVariable;

				strResult = szLongPathBuffer;
				strLeft    = strResult.Left(nFirstPos);
				strRight   = strResult.Mid (nSecondPos + 1);
				strEnvName = strResult.Mid(nFirstPos + 1, nSecondPos - nFirstPos - 1);
				TCHAR szTempBuf[MAX_PATH];
				DWORD dwResult = GetEnvironmentVariable(strEnvName.GetBuffer(), szTempBuf, MAX_PATH);
				if (dwResult > 0)
					strEnvVariable = szTempBuf;

				strResult = CombinationPath(strLeft, strEnvVariable, L"");
				strResult += strRight;
			}
			else
			{
				strResult = szLongPathBuffer;
			}
			goto Exit0;

		}
	}
	else if (CString("systemqueuefiles").CompareNoCase(pszName) == 0)
	{
		DWORD len = sizeof(szLongPathBuffer);
		GetRegistryValue(HKEY_LOCAL_MACHINE,
			L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VolumeCaches\\Windows Error Reporting System Queue Files",
			L"Folder",
			NULL,
			(LPBYTE)szLongPathBuffer,
			&len
			);
		if (wcslen(szLongPathBuffer) == 0)
		{
			strResult = L"%systemqueuefiles%";
		}
		else
		{
			int nFirstPos  = 0; 
			int nSecondPos = 0;
			BOOL bFind = FALSE;
			bFind = FindEnvironmentPos(szLongPathBuffer, nFirstPos, nSecondPos);
			if(bFind)
			{
				CString strLeft       ;
				CString strRight      ;
				CString strEnvName    ;
				CString strEnvVariable;

				strResult = szLongPathBuffer;
				strLeft    = strResult.Left(nFirstPos);
				strRight   = strResult.Mid (nSecondPos + 1);
				strEnvName = strResult.Mid(nFirstPos + 1, nSecondPos - nFirstPos - 1);
				TCHAR szTempBuf[MAX_PATH];
				DWORD dwResult = GetEnvironmentVariable(strEnvName.GetBuffer(), szTempBuf, MAX_PATH);
				if (dwResult > 0)
					strEnvVariable = szTempBuf;

				strResult = CombinationPath(strLeft, strEnvVariable, L"");
				strResult += strRight;
			}
			else
			{
				strResult = szLongPathBuffer;
			}
			goto Exit0;

		}
	}
    else if ( CString("tudou").CompareNoCase(pszName) == 0 )
    {
         DWORD len = sizeof(szLongPathBuffer);
         GetRegistryValue(HKEY_LOCAL_MACHINE,
             L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\飞速土豆",
             L"UninstallString",
             NULL,
             (LPBYTE)szLongPathBuffer,
             &len
             );
         if(wcslen(szLongPathBuffer) == 0)
            strResult = L"%tudou%";
         else
         {
             ::PathRemoveFileSpec(szLongPathBuffer);
             ::PathAppend(szLongPathBuffer,L"tudouva.ini");
             IniEditor IniEdit;
             IniEdit.SetFile(szLongPathBuffer);
             std::wstring tmpPath = IniEdit.ReadString(L"public",L"savedirectory");
             if(tmpPath.length() <= 3)
                 strResult = L"%tudou%";
             else 
                 strResult = tmpPath.c_str();

         }

        goto Exit0;
    }else if ( CString("qvod").CompareNoCase(pszName) == 0 )
    {
        DWORD len = sizeof(szBuffer);
        GetRegistryValue(HKEY_LOCAL_MACHINE,
            L"SOFTWARE\\QvodPlayer\\Insert",
            L"Insertpath",
            NULL,
            (LPBYTE)szLongPathBuffer,
            &len
            );
        if(wcslen(szLongPathBuffer) == 0)
            strResult = L"%qvod%";
        else
        {
            //::PathRemoveFileSpec(szLongPathBuffer);
            ::PathAppend(szLongPathBuffer,L"QvodPlayer.xml");
            TiXmlDocument xmlDoc;
            const TiXmlElement *pXmlQvodPlayer = NULL;
            const TiXmlElement *pXmlGeneral = NULL;
            strResult = L"%qvod%";
            if (!xmlDoc.LoadFile(UnicodeToAnsi(szLongPathBuffer).c_str(), TIXML_ENCODING_UTF8))
                goto Exit0;
            pXmlQvodPlayer = xmlDoc.FirstChildElement("QvodPlayer");
            if (!pXmlQvodPlayer)
                goto Exit0;
            pXmlGeneral = pXmlQvodPlayer->FirstChildElement("General");
            if (pXmlGeneral)
            {
                const char* szTmp = pXmlGeneral->Attribute("Defaultsavepath");
                if(!szTmp)
                    strResult = L"%qvod%";
                else 
                    strResult = Utf8ToUnicode(szTmp).c_str();
            }

        }

        goto Exit0;
    }
    else if ( CString("xunleikankan").CompareNoCase(pszName) == 0 )
    {
        DWORD len = sizeof(szBuffer);
        GetRegistryValue(HKEY_LOCAL_MACHINE,
            L"SOFTWARE\\Thunder network\\Xmp",
            L"storepath",
            NULL,
            (LPBYTE)szBuffer,
            &len
            );
        if(wcslen(szBuffer) == 0)
            strResult = L"%xunleikankan%";
        else
        {
//            wcscat(szBuffer,L"\\VODCache");
            strResult =szBuffer;
        }

        goto Exit0;
    }
    else if ( CString("youku").CompareNoCase(pszName) == 0 )
    {
        DWORD len = sizeof(szBuffer);
        GetRegistryValue(HKEY_CURRENT_USER,
            L"SOFTWARE\\youku\\iKuAcc",
            L"CachePath",
            NULL,
            (LPBYTE)szBuffer,
            &len
            );
        if(wcslen(szBuffer) == 0)
            strResult = L"%youku%";
        else
        {
            strResult =szBuffer;
            if(strResult.Find(L"\\Desktop")!=-1)
                strResult = L"%youku%";
        }

        goto Exit0;
    }
    else if ( CString("ku6").CompareNoCase(pszName) == 0 )
    {
        DWORD len = sizeof(szLongPathBuffer);
        GetRegistryValue(HKEY_LOCAL_MACHINE,
            L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Ku6SpeedUpper",
            L"UninstallString",
            NULL,
            (LPBYTE)szLongPathBuffer,
            &len
            );
        if(wcslen(szLongPathBuffer) == 0)
        {
            CString StrSuffix = _T("\\kvideo_cache");;
            strResult = GetDrive(StrSuffix);
        }
        else
        {
            ::PathRemoveFileSpec(szLongPathBuffer);
            ::PathAppend(szLongPathBuffer,L"Ku6SpeedUpper.ini");
            IniEditor IniEdit;
            IniEdit.SetFile(szLongPathBuffer);
            std::wstring tmpPath = IniEdit.ReadString(L"Settings",L"BufPath");
            if(tmpPath.length() > 0)
                strResult = tmpPath.c_str();
            else
            {
                CString StrSuffix = _T("\\kvideo_cache");;
                strResult = GetDrive(StrSuffix);
                
            }
        }
        goto Exit0;
    }
    else if ( CString("ppstream").CompareNoCase(pszName) == 0 )
    {
        CString strTmp = GetFolderPath(L"CSIDL_APPDATA");
        strTmp += L"\\ppstream\\psnetwork.ini";
        if(!::PathFileExists(strTmp.GetBuffer()))
        {
            strTmp = L"";
            GetWindowsDirectory(szLongPathBuffer,MAX_PATH);
            strTmp = szLongPathBuffer;
            strTmp +=  L"\\psnetwork.ini";
        }
        IniEditor IniEdit;
        IniEdit.SetFile(strTmp.GetBuffer());
        std::wstring tmpPath = IniEdit.ReadString(L"vodnet",L"pgfpath");
        if(tmpPath.length()>0)
          ::PathRemoveFileSpec((LPWSTR)tmpPath.c_str());
        else
        {
            tmpPath = IniEdit.ReadString(L"vodnet",L"pgfpath1");
            if(tmpPath.length()>0)
                tmpPath.erase(tmpPath.length()-1);
        }
        strResult = tmpPath.c_str();
        goto Exit0;
    }
    else if ( CString("pptv").CompareNoCase(pszName) == 0 )
    {
        CString strTmp = GetFolderPath(L"CSIDL_COMMON_APPDATA");
        strTmp += L"\\PPLive\\Core\\config.ini";
        IniEditor IniEdit;
        IniEdit.SetFile(strTmp.GetBuffer());
        std::wstring tmpPath = IniEdit.ReadString(L"peer",L"cachepath");
        std::string utf8str = KUTF16_To_ANSI(tmpPath.c_str());
        tmpPath = Utf8ToUnicode(utf8str.c_str());
        if(tmpPath.length() == 0)
            strResult = L"%pptv%";
        else
            strResult = tmpPath.c_str();
        goto Exit0;
    }
    else if ( CString("fengxing").CompareNoCase(pszName) == 0 )
    {
        CString strTmp = GetFolderPath(L"CSIDL_PERSONAL");
        int a = strTmp.ReverseFind(L'\\');
        strTmp = strTmp.Mid(0,strTmp.ReverseFind(L'\\'));
        strTmp += L"\\funshion.ini";
        IniEditor IniEdit;
        IniEdit.SetFile(strTmp.GetBuffer());
        std::wstring tmpPath = IniEdit.ReadString(L"FILE_PATH",L"MEDIA_PATH");
        if(tmpPath.length() == 0)
            strResult = L"%fengxing%";
        else
            strResult = tmpPath.c_str();
        goto Exit0;
    }
    else if ( CString("qqlive").CompareNoCase(pszName) == 0 )
    {
       CString strTmp = GetFolderPath(L"CSIDL_APPDATA");
       strTmp += L"\\Tencent\\QQLive\\user.ini";
       IniEditor IniEdit;
       IniEdit.SetFile(strTmp.GetBuffer());
       std::wstring tmpPath = IniEdit.ReadString(L"Cache",L"Directory");
       if(tmpPath.length()>0)
       {
           tmpPath.erase(tmpPath.length()-1);
           strResult = tmpPath.c_str();
       }
       else strResult = L"%qqlive%";
       
       goto Exit0;
    }
	else if ( CString("firefox").CompareNoCase(pszName) == 0 )
	{
		WCHAR szPath[MAX_PATH] = {0};
		SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE);
		std::wstring strPath;
		std::wstring strTemp;
		strPath = szPath;
		HANDLE hFile = INVALID_HANDLE_VALUE;
		if (strPath.rfind(L'\\') != strPath.size())
		{
			strPath += L"\\";
		}
		strPath += L"Mozilla\\Firefox\\profiles.ini";
		IniEditor inif;
		inif.SetFile(strPath.c_str());
		strTemp = inif.ReadString(L"Profile0", L"Path");
		if(strTemp.find(L"//") != -1)
		{
			strTemp.replace(strTemp.find(L"//"), 1, L"\\");
		}

		ZeroMemory(szPath, MAX_PATH);
		SHGetSpecialFolderPath(NULL, szPath, CSIDL_LOCAL_APPDATA, FALSE);
		strPath = szPath;
		if (strPath.rfind(L'\\') != strPath.size())
		{
			strPath += L"\\";
		}
		strPath += L"Mozilla\\Firefox\\";
		strPath += strTemp;
		strPath += L"\\cache";

		strResult = strPath.c_str();
		goto Exit0;
	}
    else if ( CString("sogou").CompareNoCase(pszName) == 0 )
    {
        std::wstring strPath;
        std::wstring strTemp;
        WCHAR szPath[MAX_PATH] = {0};
        SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE);
        strTemp = szPath;
        if ( strTemp.rfind(L'\\') != strTemp.size())
        {
            strTemp += L"\\";
        }
        strTemp += L"SogouExplorer\\CommCfg.xml";

        strResult = L"%sogou%";
        TiXmlDocument xmlDoc;
        const TiXmlElement *pXmlSogou = NULL;
        const TiXmlElement *pXmlGeneral = NULL;
        if (!xmlDoc.LoadFile(UnicodeToAnsi(strTemp.c_str()).c_str(), TIXML_ENCODING_UTF8))
            goto Exit0;
        pXmlSogou = xmlDoc.FirstChildElement("main");
        if (!pXmlSogou)
            goto Exit0;
        pXmlGeneral = pXmlSogou->FirstChildElement("Item");
        if (pXmlGeneral && pXmlGeneral->Attribute("videoacccachepath"))
        {
            const char* szTmp = pXmlGeneral->Attribute("videoacccachepath");
            if(!szTmp)
                strResult = L"%sogou%";
            else 
                strResult = Utf8ToUnicode(szTmp).c_str();
        }
        // 过滤根目录
        if (strResult.GetLength() <= 3)
            strResult = L"%sogou%";
        goto Exit0;
    }
    else if (CString("usertemp").CompareNoCase(pszName) == 0)
    {
        TCHAR szBuffer[MAX_PATH] = { 0 };
        CString strPath;
        CString strEnvName = L"%TEMP%";
        CString strEnvPath;

        ExpandEnvironmentStrings(strEnvName, strEnvPath.GetBuffer(MAX_PATH), MAX_PATH);
        strEnvPath.ReleaseBuffer();
        
        StandardPath(strEnvPath);
    
        UINT uResult = GetSystemDirectory(szBuffer, MAX_PATH);

        if (uResult < 3 || szBuffer[1] != TEXT(':') || szBuffer[2] != TEXT('\\'))
        {
            goto Exit0;     
        }
        szBuffer[3] = TEXT('\0');
        strPath += szBuffer;
        memset(szBuffer, 0, sizeof(szBuffer));
        DWORD MaxSize = sizeof(szBuffer);
        GetUserName(szBuffer, &MaxSize);

        if (KGetWinVersion() >= 4) 
        {
            strPath += L"Users\\"; 
            strPath += szBuffer; 
            strPath += L"\\AppData\\Local\\Temp\\";
        }
        else
        {
            strPath += L"Documents and Settings\\"; 
            strPath += szBuffer; 
            strPath += L"\\Local Settings\\Temp\\";
        }
        //
        if (strPath.CompareNoCase(strEnvPath) == 0 
            || strPath.Find(strEnvPath) != -1
            || strEnvPath.Find(strPath) != -1)
        {
            strResult = L"";
        }
        else
        {
            strResult = strPath;
        }
        goto Exit0;
    }
    else if (CString("wintemp").CompareNoCase(pszName) == 0)
    {
        DWORD len = sizeof(szLongPathBuffer);
        GetRegistryValue(HKEY_LOCAL_MACHINE,
            L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
            L"TEMP",
            NULL,
            (LPBYTE)szLongPathBuffer,
            &len
            );
        if (wcslen(szLongPathBuffer) == 0)
        {
            strResult = L"";
        }
        else
        {
            if (CString("%SystemRoot%\\TEMP").CompareNoCase(szLongPathBuffer) == 0)
            {
                strResult = L"";
            }
            else
            {
                //解析环境变量
                CString strWinPath = szLongPathBuffer;

                int nFirstPos  = 0; 
                int nSecondPos = 0;
                BOOL bFind = FALSE;

                bFind = FindEnvironmentPos(strWinPath, nFirstPos, nSecondPos);
                
                if (bFind)
                {
                    CString strEnvName;
                    CString strEnvPath;
                    CString strLeft;
                    CString strRight;
                    strLeft = strWinPath.Left(nFirstPos);
                    strEnvName = strWinPath.Mid(nFirstPos, nSecondPos - nFirstPos + 1);
                    strRight = strWinPath.Mid(nSecondPos + 1);

                    ExpandEnvironmentStrings(strEnvName, strEnvPath.GetBuffer(MAX_PATH), MAX_PATH);
                    strEnvPath.ReleaseBuffer();
                    strResult += strLeft;
                    strResult += strEnvPath;
                    strResult += strRight;

                    UINT uResult = GetWindowsDirectory(szBuffer, MAX_PATH);

                    if(szBuffer[wcslen(szBuffer)-1] == _T('\\'))
                        szBuffer[wcslen(szBuffer)-1] = _T('\0');

                    CString strNormal = szBuffer;

                    strNormal += L"\\Temp\\";

                    StandardPath(strResult);

                    // 根目录跳过 和 子目录过滤,同时过滤 
                    if (strResult.GetLength() <= 3 
                        || strResult.Find(strNormal) != -1
                        || strNormal.Find(strResult) != -1)
                    {
                        strResult = L"";
                    }

                }
                else
                {
                    strResult = szLongPathBuffer;
                }
            }
        }
        goto Exit0;
    }
    else if (CString("office").CompareNoCase(pszName) == 0)
    {
        CString strDriverName;
        std::vector<CString> vecDrive;
        std::vector<CString>::iterator ite;

        TCHAR   szDriverName[500]; 

        DWORD nLength = GetLogicalDriveStrings(sizeof(szDriverName), szDriverName); 

        for (int i = 0; i < (int)nLength; i++) 
        { 
            if (szDriverName[i] != L'\0')
            {
                strDriverName += szDriverName[i]; 
            }
            else 
            { 
                strDriverName = strDriverName.Left(strDriverName.GetLength() - 1); 
                vecDrive.push_back(strDriverName); 
                strDriverName = ""; 
            } 
        }

        if (vecDrive.size() <= 0)
            goto Exit0;

        // 枚举盘符
        for (ite = vecDrive.begin(); ite != vecDrive.end(); ++ite)
        {
            CString strPath = (*ite) + _T("\\MSOCache");
            BOOL bRet = PathFileExists(strPath);

            if (bRet) 
            {
                strResult = strPath;
                break;
            }
        }
        goto Exit0;
    }
    else if (CString("qqmusic").CompareNoCase(pszName) == 0)
    {
        WCHAR szPath[MAX_PATH] = {0};
        std::wstring strPath;
        std::wstring strTemp;

        SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE);
        strPath = szPath;

        if (strPath.rfind(L'\\') != strPath.size())
        {
            strPath += L"\\";
        }
        strPath += L"Tencent\\QQMusic\\CachePath.ini";
        IniEditor inif;
        inif.SetFile(strPath.c_str());
        strTemp = inif.ReadString(L"Cache", L"Path");
        if(strTemp.find(L"//") != -1)
        {
            strTemp.replace(strTemp.find(L"//"), 1, L"\\");
        }

        strResult += strTemp.c_str();

        if (strResult.IsEmpty())
            goto Exit0;

        if (strResult[strResult.GetLength() - 1] != _T('\\'))
            strResult += _T('\\');

        strResult += L"musiccache";

        goto Exit0;
    }
    else if (CString("kuwo").CompareNoCase(pszName) == 0)
    {
        WCHAR szPath[MAX_PATH] = {0};
        std::wstring strPath;
        std::wstring strTemp;

        SHGetSpecialFolderPath(NULL, szPath, CSIDL_COMMON_APPDATA, FALSE);
        strPath = szPath;

        if (strPath.rfind(L'\\') != strPath.size())
        {
            strPath += L"\\";
        }
        strPath += L"kuwo\\conf\\user\\config.ini";
        IniEditor inif;

        inif.SetFile(strPath.c_str());
        strTemp = inif.ReadString(L"Setting", L"temppath");
        if(strTemp.find(L"//") != -1)
        {
            strTemp.replace(strTemp.find(L"//"), 1, L"\\");
        }

        strResult = strTemp.c_str();

        goto Exit0;
    }
    else if (CString("ttplayer").CompareNoCase(pszName) == 0)
    {
        DWORD len = sizeof(szLongPathBuffer);
        TCHAR szDefault[MAX_PATH * 2] = { 0 };
        SHGetSpecialFolderPath(NULL, szDefault, CSIDL_APPDATA, FALSE);
        PathAppend(szDefault, L"TTPlayer\\cache");

        GetRegistryValue(HKEY_LOCAL_MACHINE,
            L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TTPlayer",
            L"AppPath",
            NULL,
            (LPBYTE)szLongPathBuffer,
            &len
            );
        if(wcslen(szLongPathBuffer) == 0)
        {
            strResult = L"%ttplayer%";
        }
        else
        {
            ::PathRemoveFileSpec(szLongPathBuffer);
            ::PathAppend(szLongPathBuffer,L"TTPlayer.xml");
            TiXmlDocument xmlDoc;
            const TiXmlElement *pXmlTTPlayer = NULL;
            const TiXmlElement *pXmlGeneral = NULL;
            if (!xmlDoc.LoadFile(UnicodeToAnsi(szLongPathBuffer).c_str(), TIXML_ENCODING_UTF8))
                goto Exit0;

            pXmlTTPlayer = xmlDoc.FirstChildElement("ttplayer");
            if (!pXmlTTPlayer)
                goto Exit0;

            pXmlGeneral = pXmlTTPlayer->FirstChildElement("Network");
            if (pXmlGeneral)
            {
                const char* szTmp = pXmlGeneral->Attribute("CacheFolder");
                if(!szTmp)
                    strResult = L"%ttplayer%";
                else 
                    strResult = Utf8ToUnicode(szTmp).c_str();
            }
            
        }

        if (strResult.Find(szDefault) != -1 || strResult.GetLength() <= 3)
            strResult = L"%ttplayer%";

        goto Exit0;
    }
    else if (CString("ksafe").CompareNoCase(pszName) == 0)
    {
//         WCHAR szPath[MAX_PATH] = { 0 };
//         WCHAR szCmdline[MAX_PATH * 2] = { 0 };
//         ::GetModuleFileName(NULL, szPath, MAX_PATH);
// 
//         ::PathRemoveFileSpec(szPath);
//         std::wstring strIniPath = szPath;
//         std::wstring strTemp;
// 
//         strIniPath += L"\\cfg\\vulfix.ini";
// 
// //         IniEditor inif;
// // 
// //         inif.SetFile(strIniPath.c_str());
// //         strTemp = inif.ReadString(L"Main", L"downpath");
// //         if(strTemp.find(L"//") != -1)
// //         {
// //             strTemp.replace(strTemp.find(L"//"), 1, L"\\");
// //         }
// 
//         if (strTemp.length() == 0)
//         {
//             strResult = szPath;
//             strResult += L"\\hotfix";
//         }
//         else
//         {
//             strResult = strTemp.c_str();
//         }
        goto Exit0;
    }
    DWORD dwResult = GetEnvironmentVariable(pszName, szBuffer, MAX_PATH);
    if (dwResult > 0)
    {
        dwResult = 0;

        LPSTR pFileName = NULL;

        if (m_pfnGetLongPathName != NULL) 
            dwResult = m_pfnGetLongPathName(szBuffer, szLongPathBuffer, MAX_PATH);

        strResult = dwResult ? szLongPathBuffer : szBuffer;
    }
Exit0:
   
    return strResult;
}
Exemplo n.º 16
0
/*********************************************************************************************************
** 函数名称: MakeDir
** 功能描述: 建立目录
**
** 输 入: Path:路径名
**
** 输 出: RETURN_OK:成功
**        其它参考fat.h中关于返回值的说明
** 全局变量: 无
** 调用模块: strupr,ClearClus,AddFDT
********************************************************************************************************/
        acoral_u8 MakeDir(acoral_char *Path)
{
    acoral_u32 ClusIndex, Temp1;
    acoral_u8 Drive, Rt;
    FDT temp;
    
    strupr(Path);                       /* 变为大写 */

    ClusIndex = _GetFDTInfo(temp.Name, Path);
    if (ClusIndex == BAD_CLUS)
    {
        return PATH_NOT_FIND;
    }

    Drive = GetDrive(Path);
    
    /* FDT是否存在 */
    Rt = FDTIsLie(Drive, ClusIndex, temp.Name);
    if (Rt != NOT_FIND_FDT)
    {
        return Rt;
    }
    
    /* 不存在 */
    Temp1 = FATAddClus(Drive, 0);               /* 获取目录所需磁盘空间 */
    if ((Temp1 <= EMPTY_CLUS_1) || (Temp1 >= BAD_CLUS))
    {
        /* 没有空闲空间 */
        return  DISK_FULL;
    }

    ClearClus(Drive, Temp1);                /* 清空簇 */
        
        /* 设置FDT属性 */
    temp.Attr = ATTR_DIRECTORY;             
    temp.FileSize = 0;

    temp.NTRes = 0;
    temp.CrtTimeTenth = 0;
    temp.CrtTime = 0;
    temp.CrtDate = 0;
    temp.LstAccDate = 0;
    temp.WrtTime = 0;
    temp.WrtDate = 0;

    temp.FstClusLO = Temp1 & 0xffff;
    temp.FstClusHI = Temp1 / 0x10000;

    Rt = AddFDT(Drive, ClusIndex, &temp);       /* 增加目录项 */
    if (Rt == RETURN_OK)
    {
        /* 建立'.'目录 */
        temp.Name[0] = '.';
        temp.Name[1] = 0x20;
        temp.Name[2] = 0x20;
        temp.Name[3] = 0x20;
        temp.Name[4] = 0x20;
        temp.Name[5] = 0x20;
        temp.Name[6] = 0x20;
        temp.Name[7] = 0x20;
        temp.Name[8] = 0x20;
        temp.Name[9] = 0x20;
        temp.Name[10] = 0x20;
        
        AddFDT(Drive, Temp1, &temp);

        /* 建立'..'目录 */
        temp.Name[1] = '.';
        
        temp.FstClusLO = ClusIndex & 0xffff;
        temp.FstClusHI = ClusIndex / 0x10000;
        Rt = AddFDT(Drive, Temp1, &temp);
    }
    else
    {
        FATDelClusChain(Drive, Temp1);
    }
    
    return Rt;
}
Exemplo n.º 17
0
/*********************************************************************************************************
** 函数名称: GetDirClusIndex
** 功能描述: 获取指定目录开始簇号
**
** 输 入: Path:路径名
**        
** 输 出: 开始簇号,EMPTY_CLUS:为根目录
**
** 全局变量: 无
** 调用模块: strupr,GetDiskInfo,FindFDTInfo
********************************************************************************************************/
        acoral_u32 GetDirClusIndex(acoral_char *Path)
{
    acoral_char DirName[12];
    acoral_u8 Drive;
    acoral_u32 Rt;
    FDT temp;
    Disk_Info *Disk;
    
    Rt = BAD_CLUS;
    if (Path != NULL)
    {
        strupr(Path);                           /* 变为大写 */
        Drive = GetDrive(Path);                 /* 获取路基盘符 */
        if (Path[1] == ':')
        {
            Path += 2;
        }
        Disk = GetDiskInfo(Drive);              /* 获取逻辑盘信息 */
        if (Disk != NULL)
        {
            Rt = 0;
            if (Disk->FATType == FAT32)         /* FAT32 根目录 */
            {
                Rt = Disk->RootDirTable;
            }
            if (Path[0] != '\\' || Path[0] != '/')                /* 不是目录分隔符号,表明起点是当前路径 */
            {
                Rt = Disk->PathClusIndex;
            }
            else
            {
                Path++;
            }
            if (Path[0] == '.')             /* '\.'表明起点是当前路径 */
            {
                Rt = Disk->PathClusIndex;
                if (Path[1] == 0 || Path[1] == '\\' || Path[1] == '/')
                {
                    Path++;
                }
            }
            if (Path[0] == '\\' || Path[0] == '/')
            {
                Path++;
            }
            
            DirName[11] = 0;
            while (Path[0] != 0)
            {
                /* 获取子目录名 */
                StrToFDTName(DirName , Path);

                /* 子目录名开始簇号 */
                if (DirName[0] == 0x20)
                {
                    Rt = BAD_CLUS;
                    break;
                }
                /* 获取FDT信息 */
                if (FindFDTInfo(&temp, Drive, Rt, DirName) != RETURN_OK)
                {
                    Rt = BAD_CLUS;
                    break;
                }
                /* FDT是否是目录 */
                if ((temp.Attr & ATTR_DIRECTORY) == 0)
                {
                    Rt = BAD_CLUS;
                    break;
                }
                Rt = temp.FstClusLO + ((acoral_u32)(temp.FstClusHI) << 16);
                /* 字符串到下一个目录 */
                while (1)
                {
                    if (*Path == '\\' || *Path == '/')
                    {
                        Path++;
                        break;
                    }
                    if (*Path == 0)
                    {
                        break;
                    }
                    Path++;
                }
            }
        }
        if (Disk->FATType == FAT32)
        if (Rt != BAD_CLUS)
        if (Rt == Disk->RootDirTable)
        {
            Rt = 0;
        }
    }
    return Rt;
}
Exemplo n.º 18
0
CString CXTPSplitPath::GetFullPath() const
{
	return GetDrive() + GetDir();
}
Exemplo n.º 19
0
bool CZipArchive::IsDriveRemovable(LPCTSTR lpszFilePath)
{
	return GetDriveType(GetDrive(lpszFilePath)) == DRIVE_REMOVABLE;
}
Exemplo n.º 20
0
PathString PathString::ReplaceExt(const mpt::PathString &newExt) const
//--------------------------------------------------------------------
{
	return GetDrive() + GetDir() + GetFileName() + newExt;
}
int DirectoryOperations::Cd( char *path )
{
	int n;
	HANDLE hdir;
	WIN32_FIND_DATA status;

	if ( path == NULL || path[ 0 ] == '\0' )
	{
		//コンピュータ
		Free();
		items = GetDrive();

		dirs = (char **)calloc( items, sizeof( char * ) );

		for ( n = 0; n < items; ++n )
		{
			dirs[ n ] = (char *)calloc( 4, sizeof( char ) );
			dirs[ n ][ 0 ] = drive[ n ];
			dirs[ n ][ 1 ] = ':';
			dirs[ n ][ 2 ] = '\\';
		}
		strcpy_s( current, MAX_PATH, "COMPUTER" );//    strcpy( current, "COMPUTER" );

		return 0;
	} else if ( strcmp( path, ".." ) == 0 )
	{
		//1つ上に移動。
		if ( strcmp( current + 1, ":\\" ) == 0 )
		{
			return Cd( NULL );
		} else
		{
			n = strlen( current ) - 1;
			for ( --n; n >= 0; --n )
			{
				if ( current[ n ] == '\\' )
				{
					current[ n + 1 ] = '*';
					current[ n + 2 ] = '\0';
					break;
				}
			}
		}
	} else if ( strcmp( path, "." ) == 0 )
	{
		//同じ場所なので移動しない。
	} else
	{
		if ( path[ 1 ] == ':' && path[ 2 ] == '\\' )
		{
			//絶対パス。
			strcpy_s( current, MAX_PATH, path );////      strcpy( current, path );
		} else
		{
			//相対パスなので単純コピー。
			strcat_s( current, MAX_PATH, path );//      strcat( current, path );
		}
		n = strlen( current );
		if ( current[ n - 1 ] != '\\' )
		{
			current[ n++ ] = '\\';
		}
		current[ n ] = '*';
		current[ n + 1 ] = '\0';
	}

	if ( ( hdir = FindFirstFile( current, &status ) ) != INVALID_HANDLE_VALUE )
	{
		current[ strlen( current ) - 1 ] = '\0';
		Makelist( hdir, &status, 0 );
		FindClose( hdir );
	} else
	{
		current[ strlen( current ) - 1 ] = '\0';

		//ディレクトリ一覧の解放。
		Free();
		//新しく領域を作る。
	//    dirs = (char **)calloc( (items = count + (filepath[ 0 ] != '\0') + 2 ), sizeof( char * ) );
		dirs = (char **)calloc( ( items = 1 ), sizeof( char * ) );
		//1つ上に行くためのパスは用意しておく。
		dirs[ 0 ] = (char *)calloc( 3, sizeof( char ) );
		strcpy_s( dirs[ 0 ], 3, ".." );
	}

	return 0;
}
Exemplo n.º 22
0
DualErr 
Volume::DiskAccess(
	PGPUInt16			func, 
	PGPUInt8			*buf, 
	PGPUInt64			pos, 
	PGPUInt32			nBlocks, 
	GenericCallbackInfo	*upInfo)
{
	DualErr		derr;
	PIOP		pIop;
	PIOR		pIor;
	PGPBoolean	useAsync;
	PGPUInt16	offset, size;
	PVRP		pVrp;

	pgpAssertAddrValid(buf, PGPUInt8);

	pgpAssert((func == IOR_READ) || (func == IOR_WRITE));

	// Is this request asynchronous?
	useAsync = NULL!=(int)(upInfo);

	pgpAssert(Mounted());
	pgpAssertAddrValid(mPDcb, DCB);
	pgpAssert(!mVolumeReq.isInUse);

	// Prepare the request.
	mVolumeReq.isInUse = TRUE;
	
	if (useAsync)
	{
		mVolumeReq.upInfo = upInfo;
		mVolumeReq.downInfo.refData[0] = (PGPUInt32) this;
	}

	// Make sure we check that the VRP field in the DCB exists; the system
	// has a habit of nullifying it when an I/O error occurs.

	if (!(pVrp = (PVRP) mPDcb->DCB_cmn.DCB_vrp_ptr))
		derr = DualErr(kPGDMinorError_InvalidVRP);

	// Create our IOP/IOR.
	if (derr.IsntError())
	{
		size = (PGPUInt16) pVrp->VRP_max_req_size + 
			pVrp->VRP_max_sgd*sizeof(SGD);
		offset = (PGPUInt16) pVrp->VRP_delta_to_ior;

		pIop = IspCreateIop(size, offset, ISP_M_FL_INTERRUPT_TIME);

		if (!pIop)
			derr = DualErr(kPGDMinorError_IorAllocationFailed);
	}

	// Now we fill in the fields of our IOR structure prior to sending the
	// I/O request to the IOS subsystem.

	if (derr.IsntError())
	{
		pIor = &pIop->IOP_ior;
		pIop->IOP_timer_orig = pIop->IOP_timer = kDefaultIopTimeOut;

		mVolumeReq.pIor = pIor;

		pIor->IOR_next		= NULL;					// must be NULL
		pIor->IOR_func		= func;					// IOR_READ or IOR_WRITE
		pIor->IOR_status	= 0;					// result code goes here
		pIor->IOR_flags		= IORF_VERSION_002		// means we are using IOR
							| IORF_HIGH_PRIORITY			// high priority
							| IORF_LOGICAL_START_SECTOR		// in partition
							| IORF_DOUBLE_BUFFER;			// copy buffer

		// We have to set the start address, transfer count, and buffer fields
		// with the passed information.

		pIor->IOR_start_addr[0]		= GetLowDWord(pos);		// low sector
		pIor->IOR_start_addr[1]		= GetHighDWord(pos);	// high sector
		pIor->IOR_xfer_count		= nBlocks;				// # secs
		pIor->IOR_buffer_ptr		= (PGPUInt32) buf;		// buffer
		pIor->IOR_private_client	= kPGPdiskIopMagic;		// comes from us
		pIor->IOR_req_vol_handle	= (PGPUInt32) pVrp;		// vrp pointer
		pIor->IOR_sgd_lin_phys		= (PGPUInt32) (pIor + 1);	// SGDs here
		pIor->IOR_num_sgds			= 0;					// system fills in
		pIor->IOR_vol_designtr		= GetDrive();

		// Initialize the callback info.
		if (useAsync)
		{
			pIor->IOR_callback = (CMDCPLT) VolumeCallback;
			pIor->IOR_req_req_handle = (PGPUInt32) &mVolumeReq.downInfo;
		}
		else
		{
			pIor->IOR_flags |= IORF_SYNC_COMMAND;
			pIor->IOR_callback = NULL;
		}

		// The IlbIoCriteria routine must be run on the IOR in order to let
		// the system massage some of the fields in the IOR into a form that
		// it likes.

		if (!IlbIoCriteria(pIor))
			DebugOut("PGPdisk: IlbIoCriteria in DiskAccess failed");

		DebugOut(
			"PGPdisk: Vol Access IOR %X func %u pos %u nBlocks %u drive %u", 
			pIor, func, (PGPUInt32) pos, nBlocks, GetDrive());

		// Send the request to the IOS for processing synchronously.
		__asm push edi
		IOS_SendCommand(pIor, mPDcb);
		__asm pop edi

		DebugOut("PGPdisk: Exiting Vol Access IOR %X", pIor);
	}

	// If we are sync and called down the IOP we need to cleanup now
	// since there is no callback.

	if (derr.IsntError())
	{
		if (!useAsync)
		{
			derr = CleanUpRequest();	// extract derr from IOR
			mVolumeReq.isInUse = FALSE;
		}
	}

	// If an error calling down the IOP, we need to callback if we were
	// called async.

	if (derr.IsError())
	{
		if (useAsync)
		{
			CleanUpRequest();
			ScheduleAsyncCallback(derr);
		}
	}

	return derr;
}
Exemplo n.º 23
0
DualErr 
Volume::Unmount(PGPBoolean isThisEmergency)
{
	DualErr		derr;
	LockLevel	oldLock;
	PGPBoolean	hasOpenFiles, lockedDown;

	pgpAssert(Mounted());
	pgpAssert(!AttachedToLocalVolume());

	hasOpenFiles = lockedDown = FALSE;

	if (!isThisEmergency)
	{
		// Check for open files.
		derr = Driver->HasOpenFiles(mDrive, &hasOpenFiles);

		if (derr.IsntError())
		{
			if (hasOpenFiles)
				derr = DualErr(kPGDMinorError_FilesOpenOnDrive);
		}

		if (derr.IsntError())
		{
			// Flush the volume.
			VolFlush(mDrive, NULL);

			// Get a lock on the drive.
			oldLock = Driver->GetLockLevel(mDrive);
			derr = Driver->AcquireLogicalVolLock(mDrive, kLock_L3);

			lockedDown = derr.IsntError();
		}
	}

	if (derr.IsntError())
	{
		// Some people tell me this should be done to prevent hangs. (?)
		NotifyVolumeRemoval(GetDrive());

		// We make a system call to disassociate the mounted DCB with its
		// drive letter, thereby unmounting the volume.

		if (!IspDisassociateDcb(GetDrive()))
			derr = DualErr(kPGDMinorError_IspDisassocDcbFailed);
	}

	if (derr.IsntError())
	{
		CleanUpMountedVars();
	}

	if (derr.IsError())
	{
		if (lockedDown)
			Driver->AcquireLogicalVolLock(mDrive, oldLock);
	}

	return derr;
}
Exemplo n.º 24
0
int main(int argc, char *argv[])
{
    char ans[2];
    char *fileargs[64];
    char *optargs[64];
    int n_options;
    int index;
    int help_flag = 0;

#ifdef __TURBOC__
    setvect(0x23, ctrlc_hndlr);
#else
    _dos_setvect(0x23, ctrlc_hndlr);
#endif
    atexit(on_exit);
    n_options = classify_args(argc, argv, fileargs, optargs);
    for (index=0;index<n_options;index++)
        {
        if (optargs[index][0] == '?') help_flag=1;
        else
            {
            myprintf("Invalid parameter - /",0);
            myprintf(optargs[index],0); /* removed strupr */
            myprintf("\r\n",0);
            exit(1);
            } /* end else. */

        } /* end for. */

    if (help_flag)
        {
        myprintf("\r\nLABEL Version " VERSION "\r\n", 0);
        myprintf("Creates, changes or deletes the volume label of a disk.\r\n",0);
        myprintf("\r\n",0);
        myprintf("Syntax: LABEL [drive:][label] [/?]\r\n",0);
        myprintf("  [drive:]  Specifies which drive you want to label\r\n",0);
        myprintf("  [label]   Specifies the new label you want to label the drive\r\n",0);
        myprintf("  /?        Displays this help message\r\n",0);
        return 0;
        } /* end if. */

    do_cmdline(argc, argv);
    if (*Drive == '?')  /* If no drive specified, use current. */
        GetDrive();

    /* Save current directory and move to root. */
    GetCurDir(curdir);
    if (curdir[0] != 0)
        {
        *rootdir = *Drive;
        SetCurDir(rootdir);
        } /* end if. */

    /* If no label was specified, show current one first and then get new one. */
    if (*Label == '\0')
        {
        disp_label();
        get_label();
        } /* end if. */

    /* If they entered an empty label, then ask them if they want to */
    /* delete the existing volume label. */
    if ((*Label == '\0') && (!NoLabel))
        {
        do
            {
            myprintf("\nDelete current volume label (Y/N)? ",0);
            mygets(ans,2); /* WHY not use getch? ??? */
            } /* end do. */
        while (((*ans=(char)toupper(*ans)) != 'Y') && (*ans != 'N'));

        if (toupper(*ans) == 'N')
            exit(1);

        } /* end if. */

    /* Delete the old volume label. */
    del_label();

    /* Create the new one, if there is one to create. */
    if (*Label != '\0')
        {
        if (make_label())
            {
            exit(1);
            } /* end if. */

        } /* end if. */

    exit(0);
    return 0;

} /* end main. */
Exemplo n.º 25
0
bool CVolumeDescriptionEnumeratorThread::GetDrives()
{
	long drivesToHide = 0;
	// Adhere to the NODRIVES group policy
	wxRegKey key(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"));
	if (key.Exists())
	{
		if (!key.HasValue(_T("NoDrives")) || !key.QueryValue(_T("NoDrives"), &drivesToHide))
			drivesToHide = 0;
	}

	int len = GetLogicalDriveStrings(0, 0);
	if (!len)
		return false;

	wxChar* drives = new wxChar[len + 1];

	if (!GetLogicalDriveStrings(len, drives))
	{
		delete [] drives;
		return false;
	}

	const wxChar* drive_a = 0;

	const wxChar* pDrive = drives;
	while (*pDrive)
	{
		if (m_stop)
		{
			delete [] drives;
			return false;
		}

		// Check if drive should be hidden by default
		if (pDrive[0] != 0 && pDrive[1] == ':')
		{
			int bit = 0;
			char letter = pDrive[0];
			if (letter >= 'A' && letter <= 'Z')
				bit = 1 << (letter - 'A');
			if (letter >= 'a' && letter <= 'z')
				bit = 1 << (letter - 'a');

			if (drivesToHide & bit)
			{
				pDrive += wxStrlen(pDrive) + 1;
				continue;
			}
		}

		const int len = wxStrlen(pDrive);

		if ((pDrive[0] == 'a' || pDrive[0] == 'A') && !drive_a)
		{
			// Defer processing of A:, most commonly the slowest of all drives.
			drive_a = pDrive;
			pDrive += len + 1;
			continue;
		}
		if (GetDrive(pDrive, len))
		{
			wxCommandEvent evt(fzEVT_VOLUMEENUMERATED);
			m_pEvtHandler->AddPendingEvent(evt);
		}

		pDrive += len + 1;
	}

	if (drive_a)
	{
		const int len = wxStrlen(drive_a);
		if (GetDrive(drive_a, len))
		{
			wxCommandEvent evt(fzEVT_VOLUMEENUMERATED);
			m_pEvtHandler->AddPendingEvent(evt);
		}
	}

	delete [] drives;

	return true;
}