示例#1
0
bool TDBWMI::OpenDB(PGLOBAL g)
  {
  if (Use == USE_OPEN) {
    /*******************************************************************/
    /*  Table already open.                                            */
    /*******************************************************************/
    Res = Enumerator->Reset();
    N = 0;
    return false;
    } // endif use

  if (Mode != MODE_READ) {
    /*******************************************************************/
    /* WMI tables cannot be modified.                                  */
    /*******************************************************************/
    strcpy(g->Message, "WMI tables are read only");
    return true;
    } // endif Mode

  if (!To_CondFil && !stricmp(Wclass, "CIM_Datafile")
                  && !stricmp(Nspace, "root\\cimv2")) {
    strcpy(g->Message, 
      "Would last forever when not filtered, use DIR table instead");
    return true;
  } else
    DoubleSlash(g);

  Use = USE_OPEN;       // Do it now in case we are recursively called

  /*********************************************************************/
  /*  Initialize the WMI processing.                                   */
  /*********************************************************************/
  if (Initialize(g))
    return true;
  else
    return GetWMIInfo(g);

  } // end of OpenDB
示例#2
0
bool MakeZip(TCHAR *tszSource, TCHAR *tszDest, TCHAR *dbname, HWND progress_dialog)
{
    bool ret = false;
    HANDLE hSrc;
    zipFile hZip;
    SYSTEMTIME st;
    WIN32_FILE_ATTRIBUTE_DATA fad = { 0 };
    zip_fileinfo fi = { 0 };
    HWND hProgBar;
    DWORD dwRead;
    MSG msg;
    char buf[(256 * 1024)];	// 256 KB
    DWORDLONG dwSrcFileSize, dwTotalBytes = 0;

    ptrA szSourceName(mir_u2a(dbname));
    ptrT tszDestPath(DoubleSlash(tszDest));

    hSrc = CreateFile(tszSource, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hSrc == INVALID_HANDLE_VALUE)
        return ret;
    if (GetFileAttributesEx(tszSource, GetFileExInfoStandard, &fad) == FALSE)
        goto err_out;
    dwSrcFileSize = ((DWORDLONG)fad.nFileSizeLow | (((DWORDLONG)fad.nFileSizeHigh) << 32));
    if (dwSrcFileSize == 0) /* Prevent division by zero error. */
        goto err_out;
    FileTimeToLocalFileTime(&fad.ftLastWriteTime, &fad.ftLastWriteTime);
    FileTimeToSystemTime(&fad.ftLastWriteTime, &st);
    hZip = zipOpen2_64(tszDestPath, APPEND_STATUS_CREATE, NULL, NULL);
    if (hZip == NULL)
        goto err_out;
    fi.tmz_date.tm_sec = st.wSecond;
    fi.tmz_date.tm_min = st.wMinute;
    fi.tmz_date.tm_hour = st.wHour;
    fi.tmz_date.tm_mday = st.wDay;
    fi.tmz_date.tm_mon = (st.wMonth - 1);
    fi.tmz_date.tm_year = st.wYear;

    if (zipOpenNewFileInZip(hZip, szSourceName, &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION) == ZIP_OK) {
        hProgBar = GetDlgItem(progress_dialog, IDC_PROGRESS);
        while (GetWindowLongPtr(progress_dialog, GWLP_USERDATA) != 1) {
            if (!ReadFile(hSrc, buf, sizeof(buf), &dwRead, NULL))
                break;
            if (dwRead == 0) { // EOF
                ret = true;
                break;
            }
            if (zipWriteInFileInZip(hZip, buf, dwRead) != ZIP_OK)
                break;
            dwTotalBytes += dwRead;
            SendMessage(hProgBar, PBM_SETPOS, (WPARAM)((100 * dwTotalBytes) / dwSrcFileSize), 0);
            while (PeekMessage(&msg, progress_dialog, 0, 0, PM_REMOVE) != 0) {
                if (progress_dialog == NULL || !IsDialogMessage(progress_dialog, &msg)) { /* Wine fix. */
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
        }
        zipCloseFileInZip(hZip);
    }
    if (ret) {
        mir_snprintf(buf, "%s\r\n%s %s %d.%d.%d.%d\r\n",
                     Translate("Miranda NG database"), Translate("Created by:"),
                     __PLUGIN_NAME, __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM);
    }
    else {
        buf[0] = 0;
    }
    zipClose(hZip, buf);

err_out:
    CloseHandle(hSrc);

    return ret;
}