2013-04-26 17:48:26 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
Copyright (c) 2013 Lee, Jae-Hong
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCFileUtilsTizen.h"
|
|
|
|
#include "platform/CCCommon.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "CCApplication.h"
|
|
|
|
#include "cocoa/CCString.h"
|
2013-05-02 21:31:14 +08:00
|
|
|
#include <FApp.h>
|
|
|
|
#include <FBase.h>
|
|
|
|
#include <FIo.h>
|
|
|
|
#include <FText.h>
|
2013-04-26 17:48:26 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
2013-05-02 21:31:14 +08:00
|
|
|
using namespace std;
|
|
|
|
using namespace Tizen::App;
|
|
|
|
using namespace Tizen::Base;
|
|
|
|
using namespace Tizen::Io;
|
|
|
|
using namespace Tizen::Text;
|
2013-04-26 17:48:26 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FileUtils* FileUtils::sharedFileUtils()
|
2013-04-26 17:48:26 +08:00
|
|
|
{
|
|
|
|
if (s_sharedFileUtils == NULL)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
s_sharedFileUtils = new FileUtilsTizen();
|
2013-04-26 17:48:26 +08:00
|
|
|
s_sharedFileUtils->init();
|
|
|
|
}
|
|
|
|
return s_sharedFileUtils;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FileUtilsTizen::FileUtilsTizen()
|
2013-05-02 21:31:14 +08:00
|
|
|
{
|
|
|
|
}
|
2013-04-26 17:48:26 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool FileUtilsTizen::init()
|
2013-04-26 17:48:26 +08:00
|
|
|
{
|
2013-05-02 21:31:14 +08:00
|
|
|
UiApp* pApp = UiApp::GetInstance();
|
|
|
|
if (!pApp)
|
|
|
|
{
|
2013-04-26 17:48:26 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:20:27 +08:00
|
|
|
Tizen::Base::String resPath = pApp->GetAppResourcePath();
|
2013-05-02 21:31:14 +08:00
|
|
|
if (resPath.IsEmpty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-26 17:48:26 +08:00
|
|
|
|
2013-05-02 21:31:14 +08:00
|
|
|
AsciiEncoding ascii;
|
2013-05-29 09:52:45 +08:00
|
|
|
ByteBuffer* buffer = ascii.GetBytesN(resPath);
|
2013-06-15 14:03:30 +08:00
|
|
|
_defaultResRootPath = (const char *)buffer->GetPointer();
|
2013-05-29 09:52:45 +08:00
|
|
|
delete buffer;
|
2013-06-20 14:13:12 +08:00
|
|
|
return FileUtils::init();
|
2013-04-26 17:48:26 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
string FileUtilsTizen::getWritablePath()
|
2013-04-26 17:48:26 +08:00
|
|
|
{
|
2013-05-21 09:56:18 +08:00
|
|
|
UiApp* pApp = UiApp::GetInstance();
|
|
|
|
if (!pApp)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
string path("");
|
|
|
|
AsciiEncoding ascii;
|
2013-06-20 18:20:27 +08:00
|
|
|
Tizen::Base::String dataPath = pApp->GetAppDataPath();
|
2013-05-21 09:56:18 +08:00
|
|
|
if (!dataPath.IsEmpty())
|
|
|
|
{
|
2013-05-29 09:52:45 +08:00
|
|
|
ByteBuffer* buffer = ascii.GetBytesN(dataPath);
|
|
|
|
path.append((const char*)buffer->GetPointer());
|
|
|
|
delete buffer;
|
2013-05-21 09:56:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2013-04-26 17:48:26 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool FileUtilsTizen::isFileExist(const std::string& strFilePath)
|
2013-04-26 17:48:26 +08:00
|
|
|
{
|
|
|
|
std::string strPath = strFilePath;
|
|
|
|
if (!isAbsolutePath(strPath))
|
|
|
|
{ // Not absolute path, add the default root path at the beginning.
|
2013-06-15 14:03:30 +08:00
|
|
|
strPath.insert(0, _defaultResRootPath);
|
2013-04-26 17:48:26 +08:00
|
|
|
}
|
2013-05-02 21:31:14 +08:00
|
|
|
|
|
|
|
return File::IsFileExist(strPath.c_str());
|
2013-04-26 17:48:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|