changed: update version strings for beta4
[xbmc.git] / xbmc / utils / FileUtils.cpp
blob655e064c3a21b61e052d86dee1aa3c4b3700ac5b
1 #include "FileUtils.h"
2 #include "GUIWindowManager.h"
3 #include "GUIDialogYesNo.h"
4 #include "GUIDialogKeyboard.h"
5 #include "utils/log.h"
6 #include "LocalizeStrings.h"
7 #include "JobManager.h"
8 #include "FileOperationJob.h"
9 #include "Util.h"
10 #include "FileSystem/MultiPathDirectory.h"
11 #include <vector>
13 using namespace XFILE;
14 using namespace std;
16 bool CFileUtils::DeleteItem(const CFileItemPtr &item)
18 if (!item)
19 return false;
21 CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
22 if (pDialog)
24 pDialog->SetHeading(122);
25 pDialog->SetLine(0, 125);
26 pDialog->SetLine(1, CUtil::GetFileName(item->m_strPath));
27 pDialog->SetLine(2, "");
28 pDialog->DoModal();
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);
35 CFileItemList items;
36 items.Add(pItemTemp);
38 // grab the real filemanager window, set up the progress bar,
39 // and process the delete action
40 CFileOperationJob op(CFileOperationJob::ActionDelete, items, "");
42 return op.DoWork();
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);
59 bool success = false;
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))
67 success = true;
69 return success;
71 return CFile::Rename(strFileAndPath, strPath);
73 return false;