2 #include "GUIWindowManager.h"
3 #include "GUIDialogYesNo.h"
4 #include "GUIDialogKeyboard.h"
6 #include "LocalizeStrings.h"
7 #include "JobManager.h"
8 #include "FileOperationJob.h"
10 #include "FileSystem/MultiPathDirectory.h"
13 using namespace XFILE
;
16 bool CFileUtils::DeleteItem(const CFileItemPtr
&item
)
21 CGUIDialogYesNo
* pDialog
= (CGUIDialogYesNo
*)g_windowManager
.GetWindow(WINDOW_DIALOG_YES_NO
);
24 pDialog
->SetHeading(122);
25 pDialog
->SetLine(0, 125);
26 pDialog
->SetLine(1, CUtil::GetFileName(item
->m_strPath
));
27 pDialog
->SetLine(2, "");
29 if (!pDialog
->IsConfirmed()) return false;
32 // Create a temporary item list containing the file/folder for deletion
33 CFileItemPtr
pItemTemp(new CFileItem(*item
));
34 pItemTemp
->Select(true);
38 // grab the real filemanager window, set up the progress bar,
39 // and process the delete action
40 CFileOperationJob
op(CFileOperationJob::ActionDelete
, items
, "");
45 bool CFileUtils::RenameFile(const CStdString
&strFile
)
47 CStdString
strFileAndPath(strFile
);
48 CUtil::RemoveSlashAtEnd(strFileAndPath
);
49 CStdString strFileName
= CUtil::GetFileName(strFileAndPath
);
50 CStdString strPath
= strFile
.Left(strFileAndPath
.size() - strFileName
.size());
51 if (CGUIDialogKeyboard::ShowAndGetInput(strFileName
, g_localizeStrings
.Get(16013), false))
53 strPath
+= strFileName
;
54 CLog::Log(LOGINFO
,"FileUtils: rename %s->%s\n", strFileAndPath
.c_str(), strPath
.c_str());
55 if (CUtil::IsMultiPath(strFileAndPath
))
56 { // special case for multipath renames - rename all the paths.
57 vector
<CStdString
> paths
;
58 CMultiPathDirectory::GetPaths(strFileAndPath
, paths
);
60 for (unsigned int i
= 0; i
< paths
.size(); ++i
)
62 CStdString
filePath(paths
[i
]);
63 CUtil::RemoveSlashAtEnd(filePath
);
64 CUtil::GetDirectory(filePath
, filePath
);
65 CUtil::AddFileToFolder(filePath
, strFileName
, filePath
);
66 if (CFile::Rename(paths
[i
], filePath
))
71 return CFile::Rename(strFileAndPath
, strPath
);