⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win32updatemanager.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                    if (versionSize > 0)
                       data = malloc(versionSize);
                    else
                       data = NULL;   

                    // actually get the versioninfo for the file
                    if(data)
                    {
                        if(GetFileVersionInfo(filePath, dummyHandle, 
                                               versionSize, data))
                        {
                            VS_FIXEDFILEINFO* fileInfo;
                            char* fileDescription;
                            uint32 size;
                            UpdateItem* item = new UpdateItem;

                            item->SetLocalFileName(string(findData.cFileName));
                            item->SetLocalFilePath(string(filePath));

                            if(VerQueryValue(data, "\\", (void**)&fileInfo, &size))
                            {        
                                ostringstream ost;

                                //cout << filePath << ":" << endl;
                                //cout << "dwFileVersionLS: " << fileInfo->dwFileVersionLS << endl;
                                //cout << "dwFileVersionMS: " << fileInfo->dwFileVersionMS << endl;
                                //cout << "hi: " << HIWORD(fileInfo->dwFileVersionLS) << " lo: "<< LOWORD(fileInfo->dwFileVersionLS) << endl;
                                //cout << "hi: " << HIWORD(fileInfo->dwFileVersionMS) << " lo: "<< LOWORD(fileInfo->dwFileVersionMS) << endl << endl;

                                uint32 major = HIWORD(fileInfo->dwFileVersionMS);
                                uint32 minor = LOWORD(fileInfo->dwFileVersionMS);
                                uint32 rev = HIWORD(fileInfo->dwFileVersionLS);
                                uint32 file = LOWORD(fileInfo->dwFileVersionLS);

                                ost << major << "." << minor << "." << rev << "." << file;
                                
                                item->SetLocalFileVersion(ost.str());

                            }

                            // I need to learn how to correctly grab the proper language
                            // but for now we just hardcode English (US) Unicode
                            if(VerQueryValue(data, "\\StringFileInfo\\040904B0\\FileDescription", (void**)&fileDescription, &size))
                            {     
                                //cout << fileDescription << endl;
                                item->SetFileDescription(string(fileDescription));
                            }

                            //cout << endl;

                            AddItem(item);
                        }

                        free(data);
                    }
                    else // no version info, is it one of our special files?
                    {
                        const char* kHelpDescription = The_BRANDING" help file provides detailed instructions for all the "
                                                        "features in the player.";
                        const char* kThemeDescription = "This is the default theme that determines how "the_BRANDING" looks. "
                                                        "Updating the default theme will not change your theme preference if "
                                                        "you have chosen to use another theme.";
                        const char* kThemeHowToDescription = "The Theme HowTo describes how to create new themes which can be used to change "
                                                             "the default look of "the_BRANDING".";
                        const char* kChangesDescription = "The Changes file describes what has been changed between each version "
                                                          "of "the_BRANDING".";


                        if(!strcasecmp(findData.cFileName, BRANDING_HELP_FILE) ||
                           !strcasecmp(findData.cFileName, BRANDING_DEFAULT_THEME) ||
                           !strcasecmp(findData.cFileName, "ThemeHowTo.txt") ||
                           !strcasecmp(findData.cFileName, "Changes.txt"))
                        {
                            UpdateItem* item = new UpdateItem;

                            item->SetLocalFileName(string(findData.cFileName));
                            item->SetLocalFilePath(string(filePath));

                            SYSTEMTIME sysTime;

                            FileTimeToSystemTime(&findData.ftLastWriteTime, 
                                                 &sysTime);

                            ostringstream ost;

                            ost << sysTime.wYear << "-" <<
                                setw(2) << setfill('0') << sysTime.wMonth << "-" <<
                                setw(2) << setfill('0') << sysTime.wDay;

                            item->SetLocalFileTime(ost.str());

                            if(!strcasecmp(findData.cFileName, BRANDING_HELP_FILE))
                            {
                                item->SetFileDescription(string(kHelpDescription));
                            }
                            else if(!strcasecmp(findData.cFileName, BRANDING_DEFAULT_THEME))
                            {
                                item->SetFileDescription(string(kThemeDescription));
                            }
                            else if(!strcasecmp(findData.cFileName, "ThemeHowTo.txt"))
                            {
                                item->SetFileDescription(string(kThemeHowToDescription));
                            }
                            else if(!strcasecmp(findData.cFileName, "Changes.txt"))
                            {
                                item->SetFileDescription(string(kChangesDescription));
                            }

                            AddItem(item);
                        }
                    }
                }
            }

        }while(FindNextFile(findFileHandle, &findData));

        FindClose(findFileHandle);
    }

    return result;
}

Error Win32UpdateManager::GetSystemFileVersions()
{
    Error result = kError_NoErr;
    
    char filePath[MAX_PATH];
    char* fp;
    char* systemFiles[] = { "msvcrt.dll",
                            "msvcp60.dll",
                            NULL};
    uint32 index = 0;

    GetSystemDirectory(filePath, sizeof(filePath));

    strcat(filePath, "\\");
    fp = strrchr(filePath, '\\') + 1;

    while(systemFiles[index])
    {
        strcpy(fp, systemFiles[index]);

        DWORD versionSize;
        DWORD dummyHandle;
        void* data;

        versionSize = GetFileVersionInfoSize(filePath, &dummyHandle);
    
        if (versionSize > 0)
           data = malloc(versionSize);
        else
           data = NULL;   

        // actually get the versioninfo for the file
        if(data)
        {
            if(GetFileVersionInfo(filePath, dummyHandle, versionSize, data))
            {
                VS_FIXEDFILEINFO* fileInfo;
                char* fileDescription;
                uint32 size;
                UpdateItem* item = new UpdateItem;

                item->SetLocalFileName(string(systemFiles[index]));
                item->SetLocalFilePath(string(filePath));

                if(VerQueryValue(data, "\\", (void**)&fileInfo, &size))
                {        
                    ostringstream ost;

                    uint32 major = HIWORD(fileInfo->dwFileVersionMS);
                    uint32 minor = LOWORD(fileInfo->dwFileVersionMS);
                    uint32 rev = HIWORD(fileInfo->dwFileVersionLS);
                    uint32 file = LOWORD(fileInfo->dwFileVersionLS);

                    ost << major << "." << minor << "." << rev << "." << file;
                
                    item->SetLocalFileVersion(ost.str());

                }

                // I need to learn how to correctly grab the proper language
                // but for now we just hardcode English (US) Unicode
                if(VerQueryValue(data, "\\StringFileInfo\\040904B0\\FileDescription", (void**)&fileDescription, &size))
                {     
                    item->SetFileDescription(string(fileDescription));
                }

                // for the system files we set the currentFileLocation to _system_
                // to keep it from being listed in the UI... kinda kludgy...

                item->SetCurrentFileLocation(string("_system_"));

                AddItem(item);
            }

            free(data);
        }

        index++;
    }

    return result;
}


BOOL CALLBACK 
UpdateAvailableDlgProc(HWND hwnd, 
                       UINT msg, 
                       WPARAM wParam, 
                       LPARAM lParam)
{
    BOOL result = FALSE;

    switch (msg)
    {
        case WM_INITDIALOG:
        {
            
            break;
        }      

        case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                case IDCANCEL:
                    EndDialog(hwnd, FALSE);
                    break;

                case IDOK:
                {
                    EndDialog(hwnd, TRUE);
                    break;
                }
            }
  
            break;
        }
    }

    return result;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -