VirtualBox

Changeset 71137 in vbox


Ignore:
Timestamp:
Feb 27, 2018 2:47:38 PM (7 years ago)
Author:
vboxsync
Message:

VideoRec: Added timestamping output files if an output file already exists (never overwrite).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/VideoRec.cpp

    r70621 r71137  
    961961
    962962    int rc;
    963     if (pStream->uScreenID > 1)
     963    if (pCfg->aScreens.size() > 1)
    964964        rc = RTStrAPrintf(&pszFile, "%s-%u%s", pszAbsPath, pStream->uScreenID + 1, pszSuff);
    965965    else
     
    969969    {
    970970        uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_WRITE;
    971 #ifdef DEBUG
    972         fOpen |= RTFILE_O_CREATE_REPLACE;
    973 #else
     971
    974972        /* Play safe: the file must not exist, overwriting is potentially
    975973         * hazardous as nothing prevents the user from picking a file name of some
    976974         * other important file, causing unintentional data loss. */
    977975        fOpen |= RTFILE_O_CREATE;
    978 #endif
     976
    979977        RTFILE hFile;
    980978        rc = RTFileOpen(&hFile, pszFile, fOpen);
     979        if (rc == VERR_ALREADY_EXISTS)
     980        {
     981            RTStrFree(pszFile);
     982            pszFile = NULL;
     983
     984            RTTIMESPEC ts;
     985            RTTimeNow(&ts);
     986            RTTIME time;
     987            RTTimeExplode(&time, &ts);
     988
     989            if (pCfg->aScreens.size() > 1)
     990                rc = RTStrAPrintf(&pszFile, "%s-%04d-%02u-%02uT%02u-%02u-%02u-%09uZ-%u%s",
     991                                  pszAbsPath, time.i32Year, time.u8Month, time.u8MonthDay,
     992                                  time.u8Hour, time.u8Minute, time.u8Second, time.u32Nanosecond,
     993                                  pStream->uScreenID + 1, pszSuff);
     994            else
     995                rc = RTStrAPrintf(&pszFile, "%s-%04d-%02u-%02uT%02u-%02u-%02u-%09uZ%s",
     996                                  pszAbsPath, time.i32Year, time.u8Month, time.u8MonthDay,
     997                                  time.u8Hour, time.u8Minute, time.u8Second, time.u32Nanosecond,
     998                                  pszSuff);
     999
     1000            if (RT_SUCCESS(rc))
     1001                rc = RTFileOpen(&hFile, pszFile, fOpen);
     1002        }
     1003
    9811004        if (RT_SUCCESS(rc))
    9821005        {
     
    9851008            pStream->File.pszFile = pszFile; /* Assign allocated string to our stream's config. */
    9861009        }
    987         else
    988             RTStrFree(pszFile);
    9891010    }
    9901011
     
    9931014
    9941015    if (RT_FAILURE(rc))
    995         LogRel(("VideoRec: Failed to open file for screen %RU32, rc=%Rrc\n", pStream->uScreenID, rc));
     1016    {
     1017        LogRel(("VideoRec: Failed to open file '%s' for screen %RU32, rc=%Rrc\n",
     1018                pszFile ? pszFile : "<Unnamed>", pStream->uScreenID, rc));
     1019        RTStrFree(pszFile);
     1020    }
    9961021
    9971022    return rc;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette