plist文件保存有两种方式,一种是正常的像xml一样保存的,一种是二进制保存的。二进制的文件头有bplist00这个关键字。这两种文件libplist都能解析出来。
// ReadPlist.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <plist/plist.h>
#pragma comment(lib, "libplist.lib")
int main(int argc, char* argv[])
{
char file_name[MAX_PATH] = {0};
char *data = NULL;
plist_t pl = NULL;
FILE *fp = NULL;
int file_len = 0;
char *p_data = NULL;
unsigned __int32 p_len = 0;
printf("请输入文件名:");
scanf("%s", file_name);
fp = fopen(file_name, "rb");
if(!fp)
goto _out;
fseek(fp, 0, SEEK_END);
file_len = ftell(fp);
fseek(fp,0,SEEK_SET);
data = (char*)malloc(file_len);
if(!data)
goto _out;
fread(data, 1, file_len, fp);
if(memcmp(data, "bplist00", 8))
{
printf("%s n", data);
}
else
{
plist_from_bin(data, file_len, &pl);
plist_to_xml(pl, &p_data, &p_len);
printf("%s n", p_data);
}
system("pause");
_out:
if(fp)
fclose(fp);
if(pl)
plist_free(pl);
if (p_data)
free(p_data);
if(data)
delete []data;
return 0;
}
需要注意的是libplist解析出来是utf-8编码的