admin 发布的文章

http://pclive.imgo.tv/111s25fm 湖南卫视HD
http://pclive.imgo.tv/123s31fm 湖南经视HD
http://pclivecctest.imgo.tv/live/flv/123s31fm 湖南经视HD
http://pczhibo.imgo.tv/111s41fm 湖南娱乐
http://pczhibo.imgo.tv/119s21fm 湖南公共
http://pczhibo.imgo.tv/117s31fm 快乐购
http://pczhibo.imgo.tv/115s12fm 金鹰纪实
http://pczhibo.imgo.tv/125s21fm 天元围棋
http://pczhibo.imgo.tv/119s31fm 先锋记录
http://pczhibo.imgo.tv/119s41fm 先锋乒羽
http://pczhibo.imgo.tv/111s26fm 快乐垂钓
http://pczhibo.imgo.tv/117s14fm 四海钓鱼
http://pczhibo.imgo.tv/121s11fm 江苏靓妆
http://pczhibo.imgo.tv/107s25fm 金鹰卡通
http://pczhibo.imgo.tv/117s21fm 湖南国际
http://pczhibo.imgo.tv/117s41fm 青海卫视
http://pczhibo.imgo.tv/111s12fm 长沙政法
http://pczhibo.imgo.tv/109s31fm 长沙新闻
http://pczhibo.imgo.tv/115s31fm 长沙女性
http://pczhibo.imgo.tv/111s35fm CCTV-高尔夫


typedef struct SciFileHeader
{
    long lType;
    char strBuffer[52];
    long nDiskSize;
    long nFileNum;
    long nFolderNum;
    long nCommentStartAddr;
    long nCommentLen;
    long nCommentEndAddr;
    long nCoverLen;   
}SciFileHeader;

typedef struct SciBlockInfo
{
    long ChildItemAddr;
    long NextItemAddr;
    long filenamelength;
    long filetype;
    long info4;
    long filelength;
    FILETIME filetime;
}SciBlockInfo;

typedef struct TreeItem
{
    TreeItem* lpChildItem;
    TreeItem* lpNextItem;
    long filenamelength;
    long filetype;
    long info4;
    long filelength;
    SYSTEMTIME filetime;
    char strFileName[MAX_PATH];
}TreeItem;

void DeleteItem(TreeItem* lpItem);
TreeItem* NewItem();
TreeItem* ParseFile(HANDLE hFile);


void CTestMfcDlg::OnOK()
{
    DWORD nRead;
    HANDLE hFile = NULL;
    CString m_strFileName;
    HTREEITEM hRoot = NULL;
    TreeItem *lpTemp = NULL;
    SciFileHeader stFileHead;

    m_stEditCtrl.GetWindowText(m_strFileName);

    if (m_strFileName.IsEmpty())
        return;
    if (m_strFileName.GetLength() <= 0)
        return;

    if (GetFileAttributes(m_strFileName) == 0xffffffff)
        return;

    hFile = CreateFile(m_strFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    if (INVALID_HANDLE_VALUE == hFile)
        return;

    if (!ReadFile(hFile,&stFileHead,sizeof(SciFileHeader),&nRead,NULL))
        goto Exit;

    if (nRead != sizeof(SciFileHeader))
        goto Exit;

    if (stFileHead.lType != 0x46494353)
        goto Exit;

    //解析文件
    lpTemp = ParseFile(hFile);
    if (lpTemp == NULL)
        goto Exit;
    CloseHandle(hFile);

    m_strFileName.Format("%s | %d | %d | %d",stFileHead.strBuffer,stFileHead.nDiskSize,
                                             stFileHead.nFolderNum,stFileHead.nFileNum);

    //插入树中
    hRoot = m_stTreeCtrl.InsertItem(m_strFileName);
    if (hRoot == NULL)
    {
        DeleteItem(lpTemp);
        return;
    }

    InsertTreeItem(lpTemp,hRoot);
    DeleteItem(lpTemp);
    return;

Exit:
    CloseHandle(hFile);
 // TODO: Add extra validation here
}


TreeItem* ParseFile(HANDLE hFile)
{
    DWORD nRead;
    TreeItem* lpTemp;
    char strBuffer[MAX_PATH];
    SciBlockInfo stBlockInfo;

    if (hFile == NULL)
        return NULL;

    lpTemp = NULL;

    ZeroMemory(&stBlockInfo,sizeof(SciBlockInfo));

    //读取数据
    if (!ReadFile(hFile,&stBlockInfo,sizeof(SciBlockInfo),&nRead,NULL))
        return NULL;

    //判断读取是否正确
    if (nRead != sizeof(SciBlockInfo))
        return NULL;

    //校验文件长度是否正确
    if (stBlockInfo.filenamelength >= MAX_PATH)
        return NULL;

    //读取文件名
    if (!ReadFile(hFile,strBuffer,stBlockInfo.filenamelength,&nRead,NULL))
        return NULL;

    //判断读取是否正确
    if (nRead != stBlockInfo.filenamelength)
        return NULL;
   
    strBuffer[stBlockInfo.filenamelength] = '\0';

    //OK可以赋值了
    lpTemp = NewItem();
    if (lpTemp == NULL)
        return NULL;

    lpTemp->filenamelength = stBlockInfo.filenamelength;
    lpTemp->filetype       = stBlockInfo.filetype;
    lpTemp->info4          = stBlockInfo.info4;
    lpTemp->filelength     = stBlockInfo.filelength;

    CopyMemory(lpTemp->strFileName,strBuffer,MAX_PATH);

    FileTimeToSystemTime(&(stBlockInfo.filetime),&(lpTemp->filetime));

    if (stBlockInfo.ChildItemAddr != -1)
        lpTemp->lpChildItem = ParseFile(hFile);
   
    if (stBlockInfo.NextItemAddr != -1)
        lpTemp->lpNextItem = ParseFile(hFile);

    return lpTemp;
}

 

 

准备写一个将Glade/GtkBuilder等格式的UI文件转换成C++代码的python程序

首先完成的是将LIBGlade格式读取至内存中

#!/usr/bin/env python#-*- coding: utf-8 -*-

importos, sys, copyfrom xml.etree.ElementTree importElementTree'''result format:
[
{
"class" : "GtkWindow"
"id" : "window1"
"property" : [
{ "name" : "can_focus"
"value": "False"
}
{
}
]
"child" : [
{
"object":{
"class" : "GtkWindow"
"id" : "window1"
"property": [
{ "name" : "can_focus"
"value": "False"
}
{
}
]
"child" : [
...
]
}
"packing" :
{
"property": [
{ "name" : "expand"
"value": "True"
}
{
}
]
}
}
{
}
]
}
{
}
]

child_node_name = "child"
object_node_name = "widget"
packing_node_name = "packing"
''' defload_packing(parent_node):
packing
={}
propertys
=[]
tmp_property
={}#property list for property in parent_node.iterfind("property"):#name tmp_property["name"] = property.get("name")#value tmp_property["value"] =property.text#append to list propertys.append(copy.copy(tmp_property))#assign value packing["property"] =propertysreturnpackingdefload_object(parent_node):
result
={}#find widget widget = parent_node.find("widget")if widget !=None:
result[
"object"] =load_full_object(widget)#find packing packing = parent_node.find("packing")if packing !=None:
result[
"packing"] =load_packing(packing)returnresultdefload_full_object(self_node):
result
={}
propertys
=[]
childs
=[]
tmp_property
={}
tmp_child
={}#class result["class"] = self_node.get("class")#id result["id"] = self_node.get("id")#property list for property in self_node.iterfind("property"):#name tmp_property["name"] = property.get("name")#value tmp_property["value"] =property.text#other attribute if property.attrib.has_key("translatable"):
tmp_property[
"translatable"] = property.get("translatable")if property.attrib.has_key("context"):
tmp_property[
"context"] = property.get("context")if property.attrib.has_key("agent"):
tmp_property[
"agent"] = property.get("agent")if property.attrib.has_key("comments"):
tmp_property[
"comments"] = property.get("comments")#append to list propertys.append(copy.copy(tmp_property))#assign value result["property"] =propertys#childs for child in self_node.iterfind("child"):#recurse to load object tmp_child =load_object(child)#append it to list childs.append(copy.copy(tmp_child))#assign value result["child"] =childsreturnresultdefload_xml(xml_file):
result_lst
=[]#get root xml_root = ElementTree(file=xml_file).getroot()if(xml_root ==None):return -1, result_lst#check is libglade type? if (xml_root.tag != "glade-interface"):return -1, result_lstfor object in xml_root.iterfind("widget"):#print object result_lst.append(load_full_object(object))return0, result_lstif __name__=="__main__":
argNum
=len(sys.argv)#check param num if argNum <> 2:print "parameter number(%d) is not match" %argNum
sys.exit(0)

xml_file
= sys.argv[1]

ret, result
=load_xml(xml_file)print result