2014-07-30 19:20:55 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2.1 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This library 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 Lesser General Public License for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
2015-02-04 21:54:34 +03:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2014-07-30 19:20:55 +04:00
|
|
|
#include "FileUtil.h"
|
|
|
|
#include "RegistryUtil.h"
|
|
|
|
#include "UtilConstants.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
bool FileUtil::IsChildFile(const wchar_t* rootFolder, vector<wstring>* files)
|
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
for(vector<wstring>::iterator it = files->begin(); it != files->end(); it++)
|
|
|
|
{
|
|
|
|
wstring file = *it;
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
size_t found = file.find(rootFolder);
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
if(found != string::npos)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
return false;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileUtil::IsChildFile(const wchar_t* rootFolder, const wchar_t* file)
|
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
wstring* f = new wstring(file);
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
size_t found = f->find(rootFolder);
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
if(found != string::npos)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileUtil::IsChildFileOfRoot(std::vector<std::wstring>* files)
|
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
wstring* rootFolder = new wstring();
|
|
|
|
bool needed = false;
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
if(RegistryUtil::ReadRegistry(REGISTRY_ROOT_KEY, REGISTRY_FILTER_FOLDER, rootFolder))
|
|
|
|
{
|
|
|
|
if(IsChildFile(rootFolder->c_str(), files))
|
|
|
|
{
|
|
|
|
needed = true;
|
|
|
|
}
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
delete rootFolder;
|
|
|
|
return needed;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileUtil::IsChildFileOfRoot(const wchar_t* filePath)
|
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
wstring* rootFolder = new wstring();
|
|
|
|
bool needed = false;
|
|
|
|
|
|
|
|
if(RegistryUtil::ReadRegistry(REGISTRY_ROOT_KEY, REGISTRY_FILTER_FOLDER, rootFolder))
|
|
|
|
{
|
|
|
|
if(FileUtil::IsChildFile(rootFolder->c_str(), filePath))
|
|
|
|
{
|
|
|
|
needed = true;
|
|
|
|
}
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
delete rootFolder;
|
|
|
|
return needed;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|