1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*
* Copyright (C) 2010-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "FileUtils.h"
#include "guilib/GUIWindowManager.h"
#include "dialogs/GUIDialogYesNo.h"
#include "guilib/GUIKeyboardFactory.h"
#include "utils/log.h"
#include "guilib/LocalizeStrings.h"
#include "JobManager.h"
#include "FileOperationJob.h"
#include "URIUtils.h"
#include "filesystem/MultiPathDirectory.h"
#include <vector>
#include "settings/MediaSourceSettings.h"
#include "Util.h"
#include "StringUtils.h"
#include "URL.h"
#include "settings/Settings.h"
using namespace XFILE;
using namespace std;
bool CFileUtils::DeleteItem(const CStdString &strPath, bool force)
{
CFileItemPtr item(new CFileItem(strPath));
item->SetPath(strPath);
item->m_bIsFolder = URIUtils::HasSlashAtEnd(strPath);
item->Select(true);
return DeleteItem(item, force);
}
bool CFileUtils::DeleteItem(const CFileItemPtr &item, bool force)
{
if (!item || item->IsParentFolder())
return false;
CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
if (!force && pDialog)
{
pDialog->SetHeading(122);
pDialog->SetLine(0, 125);
pDialog->SetLine(1, CURL(item->GetPath()).GetWithoutUserDetails());
pDialog->SetLine(2, "");
pDialog->DoModal();
if (!pDialog->IsConfirmed()) return false;
}
// Create a temporary item list containing the file/folder for deletion
CFileItemPtr pItemTemp(new CFileItem(*item));
pItemTemp->Select(true);
CFileItemList items;
items.Add(pItemTemp);
// grab the real filemanager window, set up the progress bar,
// and process the delete action
CFileOperationJob op(CFileOperationJob::ActionDelete, items, "");
return op.DoWork();
}
bool CFileUtils::RenameFile(const CStdString &strFile)
{
CStdString strFileAndPath(strFile);
URIUtils::RemoveSlashAtEnd(strFileAndPath);
CStdString strFileName = URIUtils::GetFileName(strFileAndPath);
CStdString strPath = URIUtils::GetDirectory(strFileAndPath);
if (CGUIKeyboardFactory::ShowAndGetInput(strFileName, g_localizeStrings.Get(16013), false))
{
strPath = URIUtils::AddFileToFolder(strPath, strFileName);
CLog::Log(LOGINFO,"FileUtils: rename %s->%s\n", strFileAndPath.c_str(), strPath.c_str());
if (URIUtils::IsMultiPath(strFileAndPath))
{ // special case for multipath renames - rename all the paths.
vector<std::string> paths;
CMultiPathDirectory::GetPaths(strFileAndPath, paths);
bool success = false;
for (unsigned int i = 0; i < paths.size(); ++i)
{
CStdString filePath(paths[i]);
URIUtils::RemoveSlashAtEnd(filePath);
filePath = URIUtils::GetDirectory(filePath);
filePath = URIUtils::AddFileToFolder(filePath, strFileName);
if (CFile::Rename(paths[i], filePath))
success = true;
}
return success;
}
return CFile::Rename(strFileAndPath, strPath);
}
return false;
}
bool CFileUtils::RemoteAccessAllowed(const CStdString &strPath)
{
const unsigned int SourcesSize = 5;
CStdString SourceNames[] = { "programs", "files", "video", "music", "pictures" };
string realPath = URIUtils::GetRealPath(strPath);
// for rar:// and zip:// paths we need to extract the path to the archive
// instead of using the VFS path
while (URIUtils::IsInArchive(realPath))
realPath = CURL(realPath).GetHostName();
if (StringUtils::StartsWithNoCase(realPath, "virtualpath://upnproot/"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "musicdb://"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "videodb://"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "library://video"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "sources://video"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "special://musicplaylists"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "special://profile/playlists"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "special://videoplaylists"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "special://skin"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "special://profile/addon_data"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "addons://sources"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "upnp://"))
return true;
else if (StringUtils::StartsWithNoCase(realPath, "plugin://"))
return true;
else
{
std::string strPlaylistsPath = CSettings::Get().GetString("system.playlistspath");
URIUtils::RemoveSlashAtEnd(strPlaylistsPath);
if (StringUtils::StartsWithNoCase(realPath, strPlaylistsPath))
return true;
}
bool isSource;
for (unsigned int index = 0; index < SourcesSize; index++)
{
VECSOURCES* sources = CMediaSourceSettings::Get().GetSources(SourceNames[index]);
int sourceIndex = CUtil::GetMatchingSource(realPath, *sources, isSource);
if (sourceIndex >= 0 && sourceIndex < (int)sources->size() && sources->at(sourceIndex).m_iHasLock != 2 && sources->at(sourceIndex).m_allowSharing)
return true;
}
return false;
}
|