Changeset 23304 in vbox for trunk/src/VBox/Main
- Timestamp:
- Sep 24, 2009 5:13:41 PM (15 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r23249 r23304 53 53 # include "USBProxyService.h" 54 54 #endif 55 56 #include "VirtualBoxXMLUtil.h"57 55 58 56 #include "Logging.h" -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r23235 r23304 65 65 #include "DHCPServerImpl.h" 66 66 67 #include "VirtualBoxXMLUtil.h"68 69 67 #include "Logging.h" 70 68 … … 72 70 # include "win/svchlp.h" 73 71 #endif 74 75 // #include <stdio.h>76 // #include <stdlib.h>77 72 78 73 // defines -
trunk/src/VBox/Main/xml/Settings.cpp
r23289 r23304 24 24 #include <iprt/stream.h> 25 25 #include <iprt/ctype.h> 26 27 #include "VirtualBoxXMLUtil.h" 26 #include <iprt/file.h> 28 27 29 28 // generated header … … 34 33 using namespace com; 35 34 using namespace settings; 35 36 //////////////////////////////////////////////////////////////////////////////// 37 // 38 // Defines 39 // 40 //////////////////////////////////////////////////////////////////////////////// 41 42 /** VirtualBox XML settings namespace */ 43 #define VBOX_XML_NAMESPACE "http://www.innotek.de/VirtualBox-settings" 44 45 /** VirtualBox XML settings version number substring ("x.y") */ 46 #define VBOX_XML_VERSION "1.9" 47 48 /** VirtualBox XML settings version platform substring */ 49 #if defined (RT_OS_DARWIN) 50 # define VBOX_XML_PLATFORM "macosx" 51 #elif defined (RT_OS_FREEBSD) 52 # define VBOX_XML_PLATFORM "freebsd" 53 #elif defined (RT_OS_LINUX) 54 # define VBOX_XML_PLATFORM "linux" 55 #elif defined (RT_OS_NETBSD) 56 # define VBOX_XML_PLATFORM "netbsd" 57 #elif defined (RT_OS_OPENBSD) 58 # define VBOX_XML_PLATFORM "openbsd" 59 #elif defined (RT_OS_OS2) 60 # define VBOX_XML_PLATFORM "os2" 61 #elif defined (RT_OS_SOLARIS) 62 # define VBOX_XML_PLATFORM "solaris" 63 #elif defined (RT_OS_WINDOWS) 64 # define VBOX_XML_PLATFORM "windows" 65 #else 66 # error Unsupported platform! 67 #endif 68 69 /** VirtualBox XML settings full version string ("x.y-platform") */ 70 #define VBOX_XML_VERSION_FULL VBOX_XML_VERSION "-" VBOX_XML_PLATFORM 71 72 //////////////////////////////////////////////////////////////////////////////// 73 // 74 // Internal data 75 // 76 //////////////////////////////////////////////////////////////////////////////// 36 77 37 78 /** … … 45 86 : pParser(NULL), 46 87 pDoc(NULL), 47 pelmRoot(NULL) 88 pelmRoot(NULL), 89 sv(SettingsVersion_Null), 90 svRead(SettingsVersion_Null) 48 91 {} 49 92 … … 59 102 xml::Document *pDoc; 60 103 xml::ElementNode *pelmRoot; 104 61 105 com::Utf8Str strSettingsVersionFull; // e.g. "1.7-linux" 62 SettingsVersion_T sv; // e.g. SETTINGS_VERSION_1_7 106 SettingsVersion_T sv; // e.g. SettingsVersion_v1_7 107 108 SettingsVersion_T svRead; // settings version that the original file had when it was read, 109 // or SettingsVersion_Null if none 63 110 64 111 void cleanup() … … 110 157 } 111 158 }; 159 160 //////////////////////////////////////////////////////////////////////////////// 161 // 162 // ConfigFileBase 163 // 164 //////////////////////////////////////////////////////////////////////////////// 112 165 113 166 /** … … 199 252 if (m->sv == SettingsVersion_Null) 200 253 throw ConfigFileError(this, m->pelmRoot, N_("Cannot handle settings version '%s'"), m->strSettingsVersionFull.c_str()); 254 255 // remember the settings version we read in case it gets upgraded later, 256 // so we know when to make backups 257 m->svRead = m->sv; 201 258 } 202 259 else … … 425 482 * Creates a new stub xml::Document in the m->pDoc member with the 426 483 * root "VirtualBox" element set up. This is used by both 427 * MainConfigFile and MachineConfigFile when writing out their XML. 484 * MainConfigFile and MachineConfigFile at the beginning of writing 485 * out their XML. 428 486 * 429 487 * Before calling this, it is the responsibility of the caller to … … 459 517 460 518 default: 461 // silently upgrade if necessary519 // silently upgrade if this is less than 1.7 because that's the oldest we can write 462 520 pcszVersion = "1.7"; 463 521 m->sv = SettingsVersion_v1_7; 464 522 break; 465 523 } 524 466 525 m->pelmRoot->setAttribute("version", Utf8StrFmt("%s-%s", 467 526 pcszVersion, 468 527 VBOX_XML_PLATFORM)); // e.g. "linux" 528 529 // since this gets called before the XML document is actually written out 530 // do this, this is where we must check whether we're upgrading the settings 531 // version and need to make a backup, so the user can go back to an earlier 532 // VirtualBox version and recover his old settings files. 533 if ( (m->svRead != SettingsVersion_Null) // old file exists? 534 && (m->svRead < m->sv) // we're upgrading? 535 ) 536 { 537 // compose new filename: strip off trailing ".xml" 538 Utf8Str strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 4); 539 // and append something likd "-1.3-linux.xml" 540 strFilenameNew.append("-"); 541 strFilenameNew.append(m->strSettingsVersionFull); // e.g. "1.3-linux" 542 strFilenameNew.append(".xml"); 543 544 RTFileMove(m->strFilename.c_str(), 545 strFilenameNew.c_str(), 546 0); // no RTFILEMOVE_FLAGS_REPLACE 547 548 // do this only once 549 m->svRead = SettingsVersion_Null; 550 } 469 551 } 470 552 … … 575 657 return m->fFileExists; 576 658 } 659 660 661 //////////////////////////////////////////////////////////////////////////////// 662 // 663 // MainConfigFile 664 // 665 //////////////////////////////////////////////////////////////////////////////// 577 666 578 667 /** … … 2135 2224 } 2136 2225 2226 //////////////////////////////////////////////////////////////////////////////// 2227 // 2228 // MachineConfigFile 2229 // 2230 //////////////////////////////////////////////////////////////////////////////// 2231 2137 2232 /** 2138 2233 * Constructor. … … 2169 2264 } 2170 2265 2266 // clean up memory allocated by XML engine 2171 2267 clearDocument(); 2172 2268 }
Note:
See TracChangeset
for help on using the changeset viewer.