plutil 的 跨平台版本,基于 PlistCpp.
废话不多,放马:
- #include <cstdio>
- #include "Plist.hpp"
- using namespace std;
- typedef map<string, boost::any> Map;
- const char *link = "https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/plutil.1.html";
- const string plistHeader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- const string suffix(".plist");
- void usage(const char *name)
- {
- printf("Example:\n");
- printf("\t%s from.plist\n", name);
- printf("output file is (bin-/xml-)from.plist\n");
- printf("\tMore detail at %s\n", link);
- }
- int main(int argc, char **argv)
- {
- if (argc != 2)
- {
- usage(argv[0]);
- exit(1);
- }
- bool xml = true;
- string stringLine;
- ifstream infile;
- infile.open (argv[1]);
- getline(infile,stringLine);
- if (stringLine != plistHeader) {
- xml = false;
- }
- printf("%s is %s\n", argv[1], xml ? "xml format" : "binary format");
- /// read file
- Map dict;
- Plist::readPlist(argv[1], dict);
- string outFile(argv[1]);
- outFile.erase(outFile.rfind(suffix), suffix.length());
- if (xml) {
- outFile.append("-bin.plist");
- }
- else {
- outFile.append("-xml.plist");
- }
- printf("Convert %s to %s\n", argv[1], outFile.c_str());
- Plist::writePlistXML(outFile, dict);
- printf("Convert finished!\n");
- return 0;
- }
放出 win32 的下载链接;