示例#1
0
CFileAccess *FileAccessNew(U8 *_mask,Bool make_mask=FALSE,Bool make_dirs=FALSE)
{
  Bool valid=TRUE,old_silent;
  U8 *buf,*mask,*temp_mask;
  CFileAccess *fa=CAlloc(sizeof(CFileAccess));
  mask=MStrUtil(_mask,
    SUF_REM_LEADING|SUF_REM_TRAILING|SUF_REM_CTRL_CHARS);
  temp_mask=mask;
  fa->old_dir=StrNew(Fs->cur_dir);
  fa->old_prt=Fs->cur_prt;
  if (*mask && mask[1]==':') {
    if (Fs->cur_prt!=Drv2Prt(*mask))
      if (!Drv(*mask)) valid=FALSE;
    mask+=2;
  }
  if (StrStr(mask,"HOME") && Fs->cur_prt!=Drv2Prt(*sys_acct))
    Drv(*sys_acct);
  fa->p=Fs->cur_prt;
  PrtChk(fa->p);
  buf=MAlloc(StrLen(mask)+2);
  StrCpy(buf,mask);
  fa->mask=MAlloc(StrLen(mask)+2);
  StrLastRem(buf,"/",fa->mask);
  if (*mask=='/' && !*buf)
    StrCpy(buf,"/");
  //If began with Dir, change to Dir.
  if (*buf && !Cd(buf,make_dirs))
    valid=FALSE;
  if (valid && make_mask) {
    if (!*fa->mask) {
      Free(fa->mask);
      fa->mask=StrNew("*");
    } else {
      if (!make_dirs || FileNameChk(fa->mask)) {
	old_silent=Silent(ON);
	//Try mask to see if Dir. If Dir, change to dir and set to "*".
	if (Cd(fa->mask,make_dirs)) {
	  Free(fa->mask);
	  fa->mask=StrNew("*");
	}
	Silent(old_silent);
      }
    }
  }
  Free(buf);
  Free(temp_mask);
  if (!valid) {
    FileAccessDel(fa);
    fa=NULL;
//    throw(EXCEPT_FILE);
  }
  return fa;
}
示例#2
0
Bool IsDir(U8 *dir_name)
{
  U8 *mask=MSPrintF("%s/*",dir_name);
  Bool result,old_silent=Silent(ON);
  CFileAccess *fa;
  if (fa=FileAccessNew(mask)) {
    FileAccessDel(fa);
    result=TRUE;
  } else
    result=FALSE;
  Free(mask);
  Silent(old_silent);
  return result;
}
示例#3
0
bool WaitNoPendingInstallEvents(int timeLimit, bool repeate)
{
  typedef DWORD  (WINAPI *PWAITNOPENDINGINSTALLEVENTS)(IN DWORD);
  static PWAITNOPENDINGINSTALLEVENTS pWaitNoPendingInstallEvents = NULL;

  if(!pWaitNoPendingInstallEvents) {
    HMODULE hModule = GetModuleHandle("setupapi.dll");

    if (!hModule)
      return FALSE;

    pWaitNoPendingInstallEvents =
        (PWAITNOPENDINGINSTALLEVENTS)GetProcAddress(hModule, "CMP_WaitNoPendingInstallEvents");

    if (!pWaitNoPendingInstallEvents)
      return FALSE;
  }

  if (int(DWORD(timeLimit * 1000)/1000) != timeLimit)
    timeLimit = -1;

  bool inTrace = FALSE;
  DWORD startTime = GetTickCount();

  for (int count = 0 ;;) {
    DWORD res = pWaitNoPendingInstallEvents(0);

    if (res == WAIT_OBJECT_0) {
      if (++count < 5) {
        Sleep(100);
        continue;
      }

      if (inTrace)
        Trace(" OK\n");

      SetLastError(ERROR_SUCCESS);
      break;
    }

    count = 0;

    if (res != WAIT_TIMEOUT) {
      ShowLastError(MB_OK|MB_ICONWARNING, "CMP_WaitNoPendingInstallEvents()");
      if (inTrace)
        Trace(" FAIL\n");
      return FALSE;
    }

    DWORD timeElapsed = GetTickCount() - startTime;

    if (timeLimit != -1 && timeElapsed >= DWORD(timeLimit * 1000)) {
      if (inTrace) {
        Trace(" timeout\n");
        inTrace = FALSE;
      }

      if (!Silent() && repeate) {
        if (ShowMsg(MB_YESNO,
            "The device installation activities are still pending.\n"
            "Continue to wait?\n") == IDYES)
        {
          startTime = GetTickCount();
        } else {
          repeate = FALSE;
        }

        continue;
      }

      SetLastError(ERROR_TIMEOUT);
      break;
    }

    if (!inTrace) {
      if (timeLimit != -1)
        Trace("Waiting for no pending device installation activities (%u secs) ", (unsigned)timeLimit);
      else
        Trace("Waiting for no pending device installation activities (perpetually) ");

      inTrace = TRUE;
    }

    Sleep(1000);

    Trace(".");
  }

  return TRUE;
}
示例#4
0
BOOL InfFile::UninstallAllInfFiles(
    const char *_pClassGUID,
    const char *_pClass,
    const char *_pProvider)
{
  Trace("Scan INF files .");

  DWORD size;

  if (!SetupGetInfFileList(NULL, INF_STYLE_WIN4, NULL, 0, &size)) {
    DWORD err = GetLastError();

    Trace("\n");

    ShowError(MB_OK|MB_ICONSTOP, err, "SetupGetInfFileList()");
    return FALSE;
  }

  Trace("...");

  size += 256; // possible new INF files were added since
  char *pList = (char *)LocalAlloc(LPTR, size*sizeof(pList[0]));

  if (pList) {
    if (!SetupGetInfFileList(NULL, INF_STYLE_WIN4, pList, size, NULL)) {
      DWORD err = GetLastError();

      Trace("\n");

      ShowError(MB_OK|MB_ICONSTOP, err, "SetupGetInfFileList(%lu)", (unsigned long)size);
      LocalFree(pList);
      return FALSE;
    }
  } else {
    Trace("\n");

    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    ShowLastError(MB_OK|MB_ICONSTOP, "LocalAlloc(%lu)", (unsigned long)size);
    return FALSE;
  }

  Trace(".");

  char windir[MAX_PATH];

  size = GetEnvironmentVariable("windir", windir, sizeof(windir)/sizeof(windir[0]));

  if (!size || size >= sizeof(windir)/sizeof(windir[0])) {
    DWORD err = !size ? GetLastError() : ERROR_BUFFER_OVERFLOW;

    ShowError(MB_OK|MB_ICONSTOP, err, "GetEnvironmentVariable(windir)");

    LocalFree(pList);
    return FALSE;
  }

  char *p = pList;
  int i;
  int m;

  p = pList;
  i = 0;

  do {
    i++;
    p += lstrlen(p) + 1;
  } while (*p);

  m = i/3;

  if (m == 0)
    m = 1;

  p = pList;
  i = 0;

  do {
    if (++i%m == 0)
      Trace(".");

    char infPath[MAX_PATH];

    if (SNPRINTF(infPath, sizeof(infPath)/sizeof(infPath[0]), "%s\\inf\\%s", windir, p) > 0) {
      InfFile infFile(infPath, NULL);

      if (infFile.Compare(_pClassGUID, _pClass, _pProvider, FALSE)) {
        int res;

        if (!Silent()) {
          res = ShowMsg(MB_YESNO,
            "The file %s possible should be deleted too.\n"
            "\n"
            "%s:\n"
            "  ClassGUID = %s\n"
            "  Class = %s\n"
            "  Provider = %s\n"
            "\n"
            "Would you like to delete it?\n",
            infFile.Path(),
            infFile.Path(),
            infFile.ClassGUID(FALSE),
            infFile.Class(FALSE),
            infFile.Provider(FALSE));
        } else {
          Trace("\nThe file %s possible should be deleted too\n"
                "  ClassGUID = %s\n"
                "  Class = %s\n"
                "  Provider = %s\n",
                infFile.Path(),
                infFile.ClassGUID(FALSE),
                infFile.Class(FALSE),
                infFile.Provider(FALSE));

          res = IDNO;
        }

        if (res == IDYES) {
          Trace("\n");
          UninstallInf(infFile.Path());
        }
      }
    }

    p += lstrlen(p) + 1;
  } while (*p);

  Trace(" done.\n");

  LocalFree(pList);

  return TRUE;
}
示例#5
0
文件: msg.cpp 项目: 210230/com0com
static int ShowMsgDefault(LPCSTR pText, UINT type)
{
  return Silent() ? 0 : MessageBox(NULL, pText, title, type|MB_SETFOREGROUND);
}