- Timestamp:
- Jan 27, 2007 10:41:48 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r132 r383 56 56 #include <VBox/err.h> 57 57 #include <VBox/version.h> 58 #include <VBox/VBoxHDD.h> 58 59 59 60 #include "VBoxManage.h" … … 412 413 { 413 414 RTPrintf("VBoxManage modifyvdi <uuid>|<filename>\n" 414 " -type normal|writethrough|immutable\n" 415 " settype normal|writethrough|immutable |\n" 416 " compact\n" 415 417 "\n"); 416 418 } … … 2088 2090 } 2089 2091 2092 static DECLCALLBACK(int) vdiProgressCallback(PVM pVM, unsigned uPercent, void *pvUser) 2093 { 2094 unsigned *pPercent = (unsigned *)pvUser; 2095 2096 if (*pPercent != uPercent) 2097 { 2098 *pPercent = uPercent; 2099 RTPrintf("."); 2100 if ((uPercent % 10) == 0 && uPercent) 2101 RTPrintf("%d%%", uPercent); 2102 RTStrmFlush(g_pStdOut); 2103 } 2104 2105 return VINF_SUCCESS; 2106 } 2107 2108 2090 2109 static int handleModifyVDI(int argc, char *argv[], 2091 2110 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session) 2092 2111 { 2093 2112 HRESULT rc; 2094 char *type = NULL; 2095 2096 /* The uuid/filename and a the parameter "-type" with an argument. */ 2097 if (argc != 3) 2113 2114 /* The uuid/filename and a command */ 2115 if (argc < 2) 2098 2116 { 2099 2117 return errorSyntax(USAGE_MODIFYVDI, "Incorrect number of parameters"); 2100 }2101 2102 /* let's have a closer look at the arguments */2103 for (int i = 1; i < argc; i++)2104 {2105 if (strcmp(argv[i], "-type") == 0)2106 {2107 if (argc <= i + 1)2108 {2109 return errorArgument("Missing argument to '%s'", argv[i]);2110 }2111 i++;2112 type = argv[i];2113 }2114 else2115 {2116 return errorSyntax(USAGE_MODIFYVDI, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());2117 }2118 2118 } 2119 2119 … … 2136 2136 vdi = hardDisk; 2137 2137 } 2138 if (SUCCEEDED(rc) && hardDisk && vdi) 2139 { 2140 if (type) 2141 { 2138 2139 /* let's find out which command */ 2140 if (strcmp(argv[1], "settype") == 0) 2141 { 2142 /* hard disk must be registered */ 2143 if (SUCCEEDED(rc) && hardDisk && vdi) 2144 { 2145 char *type = NULL; 2146 2147 if (argc <= 2) 2148 { 2149 return errorArgument("Missing argument to for settype"); 2150 } 2151 type = argv[2]; 2152 2142 2153 HardDiskType_T hddType; 2143 2154 CHECK_ERROR(hardDisk, COMGETTER(Type)(&hddType)); … … 2164 2175 } 2165 2176 } 2177 else 2178 { 2179 return errorArgument("Hard disk image not registered"); 2180 } 2181 } 2182 else if (strcmp(argv[1], "compact") == 0) 2183 { 2184 ComPtr<IVirtualDiskImage> vdi; 2185 2186 /* the hard disk image might not be registered */ 2187 if (!hardDisk) 2188 { 2189 virtualBox->OpenVirtualDiskImage(Bstr(argv[0]), vdi.asOutParam()); 2190 if (!hardDisk) 2191 { 2192 return errorArgument("Hard disk image not found"); 2193 } 2194 } 2195 else 2196 vdi = hardDisk; 2197 2198 if (!vdi) 2199 return errorArgument("Invalid hard disk type. The command only works on VDI files\n"); 2200 2201 Bstr fileName; 2202 vdi->COMGETTER(FilePath)(fileName.asOutParam()); 2203 2204 /* close the file */ 2205 hardDisk = NULL; 2206 vdi = NULL; 2207 2208 unsigned uProcent; 2209 2210 RTPrintf("Shrinking '%lS': 0%%", fileName.raw()); 2211 int vrc = VDIShrinkImage(Utf8Str(fileName).raw(), vdiProgressCallback, &uProcent); 2212 if (VBOX_FAILURE(vrc)) 2213 { 2214 RTPrintf("Error while shrinking hard disk image: %Vrc\n", vrc); 2215 rc = E_FAIL; 2216 } 2217 } 2218 else 2219 { 2220 return errorSyntax(USAGE_MODIFYVDI, "Invalid parameter '%s'", Utf8Str(argv[1]).raw()); 2166 2221 } 2167 2222 return SUCCEEDED(rc) ? 0 : 1;
Note:
See TracChangeset
for help on using the changeset viewer.