VirtualBox

Changeset 4742

Show
Ignore:
Timestamp:
09/12/07 18:56:41 (1 year ago)
Author:
vboxsync
Message:

vditool: convert argv[] to Utf8 before calling internal functions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/Devices/Storage/testcase/vditool.cpp

    r4372 r4742  
    6262 
    6363/** 
     64 * Our internal functions use UTF8 
     65 */ 
     66static int FilenameToUtf8(char **pszUtf8Filename, const char *pszFilename) 
     67{ 
     68    int rc = RTStrCurrentCPToUtf8(pszUtf8Filename, pszFilename); 
     69    if (VBOX_FAILURE(rc)) 
     70        RTPrintf("Error converting filename '%s' to UTF8! (rc=%Rrc)\n", 
     71                 pszFilename, rc); 
     72    return rc; 
     73} 
     74 
     75/** 
    6476 * Prints a done message indicating success or failure. 
    6577 * @returns rc 
     
    8092{ 
    8193    RTPrintf("Creating VDI: file=\"%s\" size=%u MB...\n", 
    82              pszFilename, cMBs); 
    83     int rc = VDICreateBaseImage(pszFilename, 
    84                                 VDI_IMAGE_TYPE_NORMAL, 
    85                                 (uint64_t)cMBs * (uint64_t)(1024 * 1024), 
    86                                 "Newly created test image", NULL, NULL); 
     94            pszFilename, cMBs); 
     95 
     96    /* translate argv[] to UTF8 */ 
     97    char *pszUtf8Filename; 
     98    int rc = FilenameToUtf8(&pszUtf8Filename, pszFilename); 
     99    if (VBOX_FAILURE(rc)) 
     100        return rc; 
     101 
     102    rc = VDICreateBaseImage(pszUtf8Filename, 
     103                            VDI_IMAGE_TYPE_NORMAL, 
     104                            (uint64_t)cMBs * (uint64_t)(1024 * 1024), 
     105                            "Newly created test image", NULL, NULL); 
    87106    return PrintDone(rc); 
    88107} 
     
    93112             pszDDFilename, pszFilename); 
    94113 
     114    /* translate argv[] to UTF8 */ 
     115    char *pszUtf8Filename, *pszUtf8DDFilename; 
     116    int rc = FilenameToUtf8(&pszUtf8Filename, pszFilename); 
     117    if (VBOX_FAILURE(rc)) 
     118        return rc; 
     119    rc = FilenameToUtf8(&pszUtf8DDFilename, pszDDFilename); 
     120    if (VBOX_FAILURE(rc)) 
     121        return rc; 
     122 
    95123    /* open raw image file. */ 
    96124    RTFILE File; 
    97     int rc = RTFileOpen(&File, pszDDFilename, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE); 
     125    rc = RTFileOpen(&File, pszUtf8DDFilename, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE); 
    98126    if (VBOX_FAILURE(rc)) 
    99127    { 
     
    108136    { 
    109137        RTPrintf("Creating fixed image with size %u Bytes...\n", (unsigned)cbFile); 
    110         rc = VDICreateBaseImage(pszFilename, 
     138        rc = VDICreateBaseImage(pszUtf8Filename, 
    111139                                VDI_IMAGE_TYPE_FIXED, 
    112140                                cbFile, 
     
    117145            RTPrintf("Writing data...\n"); 
    118146            PVDIDISK pVdi = VDIDiskCreate(); 
    119             rc = VDIDiskOpenImage(pVdi, pszFilename, VDI_OPEN_FLAGS_NORMAL); 
     147            rc = VDIDiskOpenImage(pVdi, pszUtf8Filename, VDI_OPEN_FLAGS_NORMAL); 
    120148            if (VBOX_SUCCESS(rc)) 
    121149            { 
     
    148176            { 
    149177                /* delete image on error */ 
    150                 VDIDeleteImage(pszFilename); 
     178                VDIDeleteImage(pszUtf8Filename); 
    151179            } 
    152180            PrintDone(rc); 
     
    179207             "progress: 0%%", 
    180208             pszFilename); 
     209 
     210    /* translate argv[] to UTF8 */ 
     211    char *pszUtf8Filename; 
     212    int rc = FilenameToUtf8(&pszUtf8Filename, pszFilename); 
     213    if (VBOX_FAILURE(rc)) 
     214        return rc; 
     215 
    181216    unsigned uPercent = 0; 
    182     int rc = VDIConvertImage(pszFilename, ProcessCallback, &uPercent); 
     217    rc = VDIConvertImage(pszUtf8Filename, ProcessCallback, &uPercent); 
    183218    RTPrintf("\n"); 
    184219    return PrintDone(rc); 
     
    189224    RTPrintf("Dumping VDI image file=\"%s\" into the log file...\n", pszFilename); 
    190225    PVDIDISK pVdi = VDIDiskCreate(); 
    191     int rc = VDIDiskOpenImage(pVdi, pszFilename, VDI_OPEN_FLAGS_READONLY); 
     226 
     227    /* translate argv[] to UTF8 */ 
     228    char *pszUtf8Filename; 
     229    int rc = FilenameToUtf8(&pszUtf8Filename, pszFilename); 
     230    if (VBOX_FAILURE(rc)) 
     231        return rc; 
     232    rc = VDIDiskOpenImage(pVdi, pszUtf8Filename, VDI_OPEN_FLAGS_READONLY); 
    192233    if (VBOX_SUCCESS(rc)) 
    193234    { 
     
    202243    RTPrintf("Resetting geometry info of VDI image file=\"%s\"\n", pszFilename); 
    203244    PVDIDISK pVdi = VDIDiskCreate(); 
    204     int rc = VDIDiskOpenImage(pVdi, pszFilename, VDI_OPEN_FLAGS_NORMAL); 
     245 
     246    /* translate argv[] to UTF8 */ 
     247    char *pszUtf8Filename; 
     248    int rc = FilenameToUtf8(&pszUtf8Filename, pszFilename); 
     249    if (VBOX_FAILURE(rc)) 
     250        return rc; 
     251 
     252    rc = VDIDiskOpenImage(pVdi, pszUtf8Filename, VDI_OPEN_FLAGS_NORMAL); 
    205253    if (VBOX_SUCCESS(rc)) 
    206254    { 
     
    218266             "progress: 0%%", 
    219267             pszSrcFile, pszDstFile); 
     268 
     269    /* translate argv[] to UTF8 */ 
     270    char *pszUtf8SrcFile, *pszUtf8DstFile; 
     271    int rc = FilenameToUtf8(&pszUtf8SrcFile, pszSrcFile); 
     272    if (VBOX_FAILURE(rc)) 
     273        return rc; 
     274    rc = FilenameToUtf8(&pszUtf8DstFile, pszDstFile); 
     275    if (VBOX_FAILURE(rc)) 
     276        return rc; 
     277 
    220278    unsigned uPrecent = 0; 
    221     int rc = VDICopyImage(pszDstFile, pszSrcFile, NULL, ProcessCallback, &uPrecent); 
     279    rc = VDICopyImage(pszUtf8DstFile, pszUtf8SrcFile, NULL, ProcessCallback, &uPrecent); 
    222280    RTPrintf("\n"); 
    223281    return PrintDone(rc); 
     
    229287             pszSrcFile, pszDstFile); 
    230288    PVDIDISK pVdi = VDIDiskCreate(); 
    231     int rc = VDIDiskOpenImage(pVdi, pszSrcFile, VDI_OPEN_FLAGS_NORMAL); 
     289 
     290    /* translate argv[] to UTF8 */ 
     291    char *pszUtf8SrcFile, *pszUtf8DstFile; 
     292    int rc = FilenameToUtf8(&pszUtf8SrcFile, pszSrcFile); 
     293    if (VBOX_FAILURE(rc)) 
     294        return rc; 
     295    rc = FilenameToUtf8(&pszUtf8DstFile, pszDstFile); 
     296    if (VBOX_FAILURE(rc)) 
     297        return rc; 
     298 
     299    rc = VDIDiskOpenImage(pVdi, pszUtf8SrcFile, VDI_OPEN_FLAGS_NORMAL); 
    232300    if (VBOX_SUCCESS(rc)) 
    233301    { 
    234302        RTFILE FileDst; 
    235         rc = RTFileOpen(&FileDst, pszDstFile, RTFILE_O_CREATE | RTFILE_O_READWRITE | RTFILE_O_DENY_WRITE); 
     303        rc = RTFileOpen(&FileDst, pszUtf8DstFile, RTFILE_O_CREATE | RTFILE_O_READWRITE | RTFILE_O_DENY_WRITE); 
    236304        if (VBOX_SUCCESS(rc)) 
    237305        { 
     
    266334             "progress: 0%%", 
    267335             pszFilename); 
     336 
     337    /* translate argv[] to UTF8 */ 
     338    char *pszUtf8Filename; 
     339    int rc = FilenameToUtf8(&pszUtf8Filename, pszFilename); 
     340    if (VBOX_FAILURE(rc)) 
     341        return rc; 
     342 
    268343    unsigned uPrecent; 
    269     int rc = VDIShrinkImage(pszFilename, ProcessCallback, &uPrecent); 
     344    rc = VDIShrinkImage(pszUtf8Filename, ProcessCallback, &uPrecent); 
    270345    RTPrintf("\n"); 
    271346    return PrintDone(rc); 
     
    278353 
    279354    RTR3Init(); 
    280     RTPrintf("vditool    Copyright (c) 2004-2005 innotek GmbH.\n\n"); 
     355    RTPrintf("vditool    Copyright (c) 2004-2007 innotek GmbH.\n\n"); 
    281356 
    282357    /* 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy