惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
S
Securelist
P
Proofpoint News Feed
D
DataBreaches.Net
Cisco Talos Blog
Cisco Talos Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
A
About on SuperTechFans
罗磊的独立博客
WordPress大学
WordPress大学
月光博客
月光博客
Latest news
Latest news
C
Cyber Attacks, Cyber Crime and Cyber Security
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
AI
AI
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
Help Net Security
Help Net Security
T
Tor Project blog
V
Vulnerabilities – Threatpost
C
Cisco Blogs
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MyScale Blog
MyScale Blog
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Forbes - Security
Forbes - Security
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
博客园 - 叶小钗
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Simon Willison's Weblog
Simon Willison's Weblog
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic

博客园 - wu.g.q

旧电脑适合的系统 安川机器人遇见的问题汇总 Estun机器人数据断电保持问题解决方案 安川机器人快捷键 安川机器人变量代替常量的转换关系 创建自己的代码仓库 查看Windows操作系统编码方式 wpf 元素设置焦点无效的问题 汽车知识总结 wpf - 设置滚动条拇指(Thumb)大小 C# 反序列化乱码 C# 确定文件编码格式的方法 C# 反序列化报错 XML 文档(1, 2)中有错误:不应有 <xml xmlns=''> xsd.exe语法示例 C# 获取XML文件内容的多种方式 VC6.0 dll debug C#与C++动态链接库DLL参数互传 C#调用C/C++动态库dll异常:对 PInvoke 函数调用导致堆栈不对称问题 C#动态调用C/C++的DLL
vc6.0 txt文件资源转为xaml资源
wu.g.q · 2024-04-03 · via 博客园 - wu.g.q
#include <vector>

BOOL IsFileExist(LPCTSTR lpFileName)
{
    BOOL bExist = TRUE;

    if(NULL == lpFileName)
    {
        return FALSE;
    }
    else
    {       
        HANDLE hFind = INVALID_HANDLE_VALUE;
        WIN32_FIND_DATA DataFind;
        hFind = FindFirstFile(lpFileName, &DataFind);
        if(INVALID_HANDLE_VALUE == hFind)
        {
            bExist = FALSE;
        }
        else
        {
            FindClose(hFind);
            
        }       
    }
    
    return bExist;
}

wchar_t* UTF8FileName(const char* utf8FilePath) {
    int wchars_num = MultiByteToWideChar(CP_UTF8, 0, utf8FilePath, -1, NULL, 0);
    wchar_t* wstr = new wchar_t[wchars_num];
    MultiByteToWideChar(CP_UTF8, 0, utf8FilePath, -1, wstr, wchars_num);
    return wstr;
}

void ConvertANSIToUTF8(const char* ansiFilePath, const char* utf8FilePath) {
    // Open the ANSI file for reading
    FILE* ansiFile = fopen(ansiFilePath, "rb");
    if (!ansiFile) {
        perror("Error opening file");
        return;
    }
 
    // Create a file for writing in UTF-8
    FILE* utf8File = _wfopen(UTF8FileName(utf8FilePath), L"wb");
    if (!utf8File) {
        fclose(ansiFile);
        perror("Error opening file");
        return;
    }
 
    // Convert ANSI to UTF-8
    int ansiChar;
    while ((ansiChar = fgetc(ansiFile)) != EOF) {
        // Convert ANSI char to wide char
        wchar_t wideChar = MultiByteToWideChar(CP_ACP, 0, (char*)&ansiChar, 1, NULL, 0);
        wchar_t wbuf[2];
        wbuf[0] = (wchar_t)ansiChar;
        wbuf[1] = 0;
 
        // Convert wide char to UTF-8
        char utf8[4];
        int utf8Bytes = WideCharToMultiByte(CP_UTF8, 0, wbuf, 1, utf8, sizeof(utf8), NULL, NULL);
 
        // Write UTF-8 bytes to file
        fwrite(utf8, 1, utf8Bytes, utf8File);
    }
    
    // Close files
    fclose(ansiFile);
    fclose(utf8File);
}



void CFileTransDlg::OnOK() 
{
    // TODO: Add extra validation here
    
    std::vector<CKeyValue> listkey;
    
    

    CKeyValue keyValueObject;

    CStdioFile file;
    if(!file.Open(_T("D:\\File\\polxp.txt"), CFile::modeRead))
    {
        return;
    }

    CStringArray strArrayKey;
    CStringArray strArrayValue;

    CString szBuffer;
    CString groupName = "";

    while(file.ReadString(szBuffer) != NULL) {
        
        int index = szBuffer.Find(_T("="));
        if(index == -1)
        {
            if(szBuffer.Find("[FILE_VER]") != -1 || szBuffer.Find("[STRINGTABLE]") != -1)
                continue;
            else if(szBuffer.Find("[") != -1)
            {
                int index2 = szBuffer.Find("[");
                groupName = szBuffer.Mid(index2+1);
                index2 = groupName.Find("]");
                groupName = groupName.Left(index2);
            }    
        }
        
        CString key = "";
        CString value = "";

        if(groupName == "")
        {
            key = szBuffer.Left(index);
        }
        else
        {
            key = groupName + "_" + szBuffer.Left(index);
        }
        
        value = szBuffer.Mid(index+1);
        value.Replace(_T("\""), _T(""));

        strArrayKey.Add(key);
        strArrayValue.Add(value);
    }
    file.Close();


    CStringArray strArrayKeyXml;
    CStringArray strArrayKeyValueAfterXml;

    if(!file.Open(_T("D:\\File\\jpn.xaml"), CFile::modeRead))
    {
        return;
    }
    while(file.ReadString(szBuffer) != NULL) {
        
        int index = szBuffer.Find(_T(">"));
        int index2 = szBuffer.Find(_T("x:Key"));

        if(index == -1 || index2 == -1)
            continue;
        
        CString key = szBuffer.Left(index+1);        
        strArrayKeyXml.Add(key);


        int index3 = szBuffer.ReverseFind('<');
        CString keyValueAfter = szBuffer.Mid(index3);
        strArrayKeyValueAfterXml.Add(keyValueAfter);
    }
    file.Close();



    for(int i = 0 ; i < strArrayKeyXml.GetSize(); i++)
    {
        CString strAllKey= strArrayKeyXml.GetAt(i);


        int index = strAllKey.Find(_T("x:Key=\""));
        if(index != -1)
        {
            CString strKey = strAllKey.Mid(index+7);
            int index2 = strKey.Find(_T("\""));

            if(index2 != -1)
            {

                strKey = strKey.Left(index2);

                strcpy(keyValueObject.allKey, strAllKey);
                strcpy(keyValueObject.key, strKey);
                strcpy(keyValueObject.keyValue, _T(""));
                            
                for(int j = 0 ; j < strArrayKey.GetSize(); j++)
                {
                    CString strKeyArr = strArrayKey.GetAt(j);
                    if(strcmp(strKeyArr, strKey) == 0)
                    {
                        CString strValue = strArrayValue.GetAt(j);

                        strValue.Replace("\\r\\n", "&#x0A;");
                        strValue.Replace("\\n", "&#x0A;");
                        strValue.Replace("<", "&lt;");
                        strValue.Replace("%03d", "{0:D3}");

                        strValue.Replace("%f", "{0:F}");
                        strValue.Replace("%d", "{0:D}");
                        strValue.Replace("%s", "{0}");
                        

                        strcpy(keyValueObject.keyValue, strValue);
                         break;
                    }
                }


                CString strKeyValueAfter = strArrayKeyValueAfterXml.GetAt(i);
                strcpy(keyValueObject.keyValueAfter, strKeyValueAfter);
                
                listkey.push_back(keyValueObject);
            }
        }
    }
    
    if (IsFileExist(_T("D:\\File\\polxp_local.xaml")))
    {
        CFile::Remove(_T("D:\\File\\polxp_local.xaml"));
    }

    if (IsFileExist(_T("D:\\File\\polxp_utf8.xaml")))
    {
        CFile::Remove(_T("D:\\File\\polxp_utf8.xaml"));
    }

    if (IsFileExist(_T("D:\\File\\polxp.xaml")))
    {
        CFile::Remove(_T("D:\\File\\polxp.xaml"));
    }


    if(file.Open(_T("D:\\File\\polxp_local.xaml"), CFile::modeWrite | CFile::modeCreate))
    {
        
        CString strTitle = "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n";
        file.WriteString(strTitle);

        strTitle = "                    xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n";
        file.WriteString(strTitle);
        
        strTitle = "                    xmlns:sys=\"clr-namespace:System;assembly=mscorlib\">\n";
        file.WriteString(strTitle);

        for(int k = 0 ; k < listkey.size(); k++)
        {
            keyValueObject = listkey[k];

            CString strLine = CString(keyValueObject.allKey) + CString(keyValueObject.keyValue) + CString(keyValueObject.keyValueAfter) + CString("\n");


            file.WriteString(strLine);
            
        }
        strTitle = "</ResourceDictionary>";
        file.WriteString(strTitle);
        
        file.Close();
    }


    //ConvertANSIToUTF8(_T("D:\\File\\polxp_local.xaml"), _T("D:\\File\\polxp_utf8.xaml"));
}