65.9K
CodeProject 正在变化。 阅读更多。
Home

FAT-32 分类器

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.83/5 (3投票s)

2012 年 5 月 29 日

CPOL

1分钟阅读

viewsIcon

20097

downloadIcon

20

更新“FAT-32 分类器”,帮助在排序时忽略前面的“the ”

介绍 

添加了命令行参数,用于在比较文件名和文件夹名时忽略开头的“the ”。

背景 

有一些车主抱怨他们的车载主机不尊重 USB 驱动器或 MP3 播放器上文件和文件夹的字母顺序,而是遵循它们在物理位置上的顺序(包括本田和丰田的最新型号)。该项目的出色工作尤其适用于解决上述问题。应用于音乐文件夹时,忽略开头的“the ”会很好,因为许多音乐播放器会自动执行此操作。

使用代码

命令行 (第一次更改)

在 `main` 函数中添加了对 `ignoreThe` 命令行参数的检查,并设置了全局标志 `ignoreTheInFolderCompare`: 

std::vector<tstring> params(argv, argv+argc);
tstring param(_T("ignoreThe"));
if(std::find(params.begin(), params.end(), param) != params.end())
	ignoreTheInFolderCompare = true;  

添加功能 (第二次更改)

下图显示了原始的目录条目排序顺序。此顺序未更改,但最后一步的实现扩展为使用上述命令行参数和全局标志(以橙色突出显示)。 

 

重写了 `comapreEntries` 方法,以实现上述功能以及以下描述的一般改进。

使用 STL 隐藏指针操作

通过替换 

WCHAR* o1Name = o1->getName();
...
bool ret = (_wcsicmp(o1Name, o2Name) <= 0); 

为 

wstring o1Name(o1->getName());
...
bool ret = (o1Name.compare(o2Name) <= 0);

移除开头的“the ” 

if (o1Name.length() > 4 && !o1Name.compare(0, prefix.size(), prefix))
    o1Name = o1Name.substr(4);
if (o2Name.length() > 4 && !o2Name.compare(0, prefix.size(), prefix))
    o2Name = o2Name.substr(4);  

全新的 `compareEntries` 方法

// This utility function is used by the std::sort function. 
// This function help to determine if two entries are in the right order, or needed to be switched
bool compareEntries( CEntry* o1, CEntry* o2)
{
    wstring o1Name(o1->getName());
    wstring o2Name(o2->getName());

    if(ignoreTheInFolderCompare)
    {
        transform(o1Name.begin(), o1Name.end(), o1Name.begin(), tolower);
        transform(o2Name.begin(), o2Name.end(), o2Name.begin(), tolower);
        wstring prefix(L"the ");
        if (o1Name.length() > 4 && !o1Name.compare(0, prefix.size(), prefix))
            o1Name = o1Name.substr(4);
        if (o2Name.length() > 4 && !o2Name.compare(0, prefix.size(), prefix))
            o2Name = o2Name.substr(4);
    }

    // Returns "true" if the entries are in the right order (o1 should be before o2)
    bool ret = (o1Name.compare(o2Name) <= 0);

    return ret;
}

	      

关注点   

我在 blogger 上发表了这篇文章,分享了另一个帮助您在“虚拟”车载立体声音响上无忧播放音乐的实用程序。该项目对于让我的汽车上的功能正常运行至关重要,希望其他人也会欣赏。

历史 

N/A

© . All rights reserved.