📄 pmp300.cpp
字号:
string itemPath = item->URL();
string downloadPath = tempPath;
downloadPath += DIR_MARKER_STR;
downloadPath.insert(downloadPath.size(),
itemPath,
itemPath.rfind('/') + 1,
itemPath.size());
RioProgressStruct ps;
memset(&ps, 0x00, sizeof(ps));
ps.function = function;
ps.cookie = cookie;
ps.item = item;
if(!rioExternal.RxFile(downloadPath.c_str(), rioProgress, &ps))
{
if(function)
{
PLMEvent event;
event.type = kPLMEvent_Error;
event.data.errorData.errorCode = rioExternal.GetErrorID();
event.eventString = "Download failed, ";
event.eventString += rioExternal.GetErrorStr();
function(&event, cookie);
}
if(rioInternal.GetErrorID() == CRIO_ERROR_INTERRUPTED)
result = kError_UserCancel;
else
result = kError_UnknownErr;
break;
}
length = _MAX_PATH;
FilePathToURL(downloadPath.c_str(), path, &length);
(*position)->SetURL(path);
}
string::size_type pos = item->URL().rfind("/") + 1;
const char* cp = item->URL().c_str();
if(!rioExternal.RemoveFile(cp + pos))
{
if(function)
{
PLMEvent event;
event.type = kPLMEvent_Error;
event.data.errorData.errorCode = rioExternal.GetErrorID();
event.eventString = "Delete failed, ";
event.eventString += rioExternal.GetErrorStr();
function(&event, cookie);
}
result = kError_UnknownErr;
break;
}
delete item;
origExternal[index] = NULL;
}
}
}
}
// if all is well we add new files
// to each card
if(IsntError(result))
{
// remove NULLs caused by deletes
origInternal.erase(
remove(origInternal.begin(),
origInternal.end(),
(PlaylistItem*)NULL),
origInternal.end());
origExternal.erase(
remove(origExternal.begin(),
origExternal.end(),
(PlaylistItem*)NULL),
origExternal.end());
// sync deletes back to the cards
rioInternal.TxDirectory();
rioExternal.TxDirectory();
if(function)
{
PLMEvent event;
event.type = kPLMEvent_Status;
event.eventString = "Uploading new files...";
function(&event, cookie);
}
count = newInternal.size();
for(index = 0; index < count; index++)
{
PlaylistItem* item = newInternal[index];
if(item->URL().find("file://") != string::npos)
{
length = _MAX_PATH;
URLToFilePath(item->URL().c_str(), path, &length);
RioProgressStruct ps;
memset(&ps, 0x00, sizeof(ps));
ps.function = function;
ps.cookie = cookie;
ps.item = item;
if(!rioInternal.TxFile(path, rioProgress, &ps))
{
if(function)
{
PLMEvent event;
event.type = kPLMEvent_Error;
event.data.errorData.errorCode = rioInternal.GetErrorID();
event.eventString = "Upload failed, ";
event.eventString += rioInternal.GetErrorStr();
function(&event, cookie);
}
if(rioInternal.GetErrorID() == CRIO_ERROR_INTERRUPTED)
result = kError_UserCancel;
else
result = kError_UnknownErr;
break;
}
origInternal.push_back(new PlaylistItem(*item));
}
}
if(IsntError(result))
{
count = newExternal.size();
for(index = 0; index < count; index++)
{
PlaylistItem* item = newExternal[index];
if(item->URL().find("file://") != string::npos)
{
length = _MAX_PATH;
URLToFilePath(item->URL().c_str(), path, &length);
RioProgressStruct ps;
memset(&ps, 0x00, sizeof(ps));
ps.function = function;
ps.cookie = cookie;
ps.item = item;
if(!rioExternal.TxFile(path, rioProgress, &ps))
{
if(function)
{
PLMEvent event;
event.type = kPLMEvent_Error;
event.data.errorData.errorCode = rioExternal.GetErrorID();
event.eventString = "Upload failed, ";
event.eventString += rioExternal.GetErrorStr();
function(&event, cookie);
}
if(rioExternal.GetErrorID() == CRIO_ERROR_INTERRUPTED)
result = kError_UserCancel;
else
result = kError_UnknownErr;
break;
}
origExternal.push_back(new PlaylistItem(*item));
}
}
}
}
// finally put it all in the correct order
// and we should be done!
if(IsntError(result))
{
uint32 entryOrder[ CRIO_MAX_DIRENTRY ];
count = newInternal.size();
if(count)
{
for(index = 0; index < count; index++)
{
vector<PlaylistItem*>::iterator position;
PlaylistItem* item = newInternal[index];
if((position = find_if(origInternal.begin(),
origInternal.end(),
PlaylistItemCompare(item))) != origInternal.end())
{
entryOrder[index] = distance(origInternal.begin(), position);
}
}
rioInternal.SetFileOrder(entryOrder, count);
}
count = newExternal.size();
if(count)
{
for(index = 0; index < count; index++)
{
vector<PlaylistItem*>::iterator position;
PlaylistItem* item = newExternal[index];
if((position = find_if(origExternal.begin(),
origExternal.end(),
PlaylistItemCompare(item))) != origExternal.end())
{
entryOrder[index] = distance(origExternal.begin(), position);
}
}
rioExternal.SetFileOrder(entryOrder, count);
}
// sync uploads back to the cards
rioInternal.TxDirectory();
rioExternal.TxDirectory();
}
if(function)
{
PLMEvent event;
event.type = kPLMEvent_Done;
function(&event, cookie);
}
// clean up
length = _MAX_PATH;
FilePathToURL(tempPath, path, &length);
strcpy(tempPath, path);
count = origInternal.size();
for(index = 0; index < count; index++)
{
PlaylistItem* item = origInternal[index];
if(item->URL().find(tempPath) != string::npos)
{
length = _MAX_PATH;
URLToFilePath(item->URL().c_str(), path, &length);
remove(path);
}
delete item;
}
count = origExternal.size();
for(index = 0; index < count; index++)
{
PlaylistItem* item = origExternal[index];
if(item->URL().find(tempPath) != string::npos)
{
length = _MAX_PATH;
URLToFilePath(item->URL().c_str(), path, &length);
remove(path);
}
delete item;
}
URLToFilePath(tempPath, path, &length);
rmdir(path);
delete [] tempPath;
delete [] path;
}
}
}
return result;
}
Error PMP300::DownloadSong(DeviceInfo* device,
PlaylistItem* item,
const char* url,
PLMCallBackFunction function,
void* cookie)
{
Error result = kError_InvalidParam;
assert(device);
assert(url);
assert(item);
if(device && url && item)
{
result = kError_DeviceNotFound;
if(!strcasecmp(device->GetDevice(), devices[0].device))
{
CRio rio;
bool rioPresent = false;
rioPresent = FindRio(rio, device, function, cookie);
if(rioPresent)
{
char* path = new char[_MAX_PATH];
uint32 length = _MAX_PATH;
URLToFilePath(url, path, &length);
string itemPath = item->URL();
string downloadPath = path;
downloadPath.replace(downloadPath.rfind(DIR_MARKER) + 1,
downloadPath.size(),
itemPath,
itemPath.rfind('/') + 1,
itemPath.size());
RioProgressStruct ps;
memset(&ps, 0x00, sizeof(ps));
ps.function = function;
ps.cookie = cookie;
ps.item = item;
result = kError_NoErr;
rio.RxDirectory();
if(!rio.RxFile(downloadPath.c_str(), rioProgress, &ps))
{
result = kError_UnknownErr;
if(rio.GetErrorID() == CRIO_ERROR_FILENOTFOUND)
{
rio.UseExternalFlash(true);
rio.RxDirectory();
if(rio.RxFile(downloadPath.c_str(), rioProgress, &ps))
{
result = kError_NoErr;
}
}
}
if(IsntError(result))
{
if(downloadPath != path)
{
if(rename(downloadPath.c_str(), path))
{
result = kError_FileNoAccess;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -