123 lines
1.9 KiB
C++
Executable File
123 lines
1.9 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "default.h"
|
|
|
|
|
|
|
|
namespace Fun
|
|
{
|
|
|
|
Default::Default()
|
|
{
|
|
fun.url = L"default";
|
|
}
|
|
|
|
|
|
long Default::PostFunDefaultParsePath()
|
|
{
|
|
Item * pdir, * pdir2;
|
|
long defaultid = -1;
|
|
|
|
const std::wstring & path = request->PostVar(L"defaultitem");
|
|
|
|
|
|
if( !path.empty() )
|
|
{
|
|
std::wstring dir, file;
|
|
Dirs::SplitPath(path, dir, file);
|
|
|
|
pdir = system->dirs.GetDir(dir);
|
|
|
|
if( !pdir )
|
|
throw Error(WINIX_ERR_INCORRECT_DIR);
|
|
|
|
if( file.empty() )
|
|
{
|
|
defaultid = pdir->id;
|
|
}
|
|
else
|
|
{
|
|
// checking whether the file is a directory too (the method SplitPath does not check it)
|
|
pdir2 = system->dirs.GetDir(file, pdir->id);
|
|
|
|
if( !pdir2 )
|
|
{
|
|
defaultid = db->GetFileId(pdir->id, file);
|
|
|
|
if( defaultid == -1 )
|
|
throw Error(WINIX_ERR_NO_ITEM);
|
|
}
|
|
else
|
|
{
|
|
// file is a directory
|
|
defaultid = pdir2->id;
|
|
}
|
|
}
|
|
}
|
|
|
|
return defaultid;
|
|
}
|
|
|
|
|
|
|
|
|
|
void Default::MakePost()
|
|
{
|
|
if( !system->HasWriteAccess(*request->dir_tab.back()) )
|
|
{
|
|
request->status = WINIX_ERR_PERMISSION_DENIED;
|
|
return;
|
|
}
|
|
|
|
|
|
try
|
|
{
|
|
long defaultid = PostFunDefaultParsePath();
|
|
|
|
if( defaultid != request->dir_tab.back()->id )
|
|
{
|
|
request->status = db->EditDefaultItem(request->dir_tab.back()->id, defaultid);
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
request->dir_tab.back()->default_item = defaultid;
|
|
}
|
|
else
|
|
{
|
|
log << "Default: skipping the same directory" << logend;
|
|
}
|
|
}
|
|
catch(const Error & e)
|
|
{
|
|
request->status = e;
|
|
}
|
|
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
system->RedirectTo(*request->dir_tab.back());
|
|
else
|
|
log << log1 << "Content: PostFunDefaultItem: Error: " << request->status << logend;
|
|
}
|
|
|
|
|
|
|
|
|
|
void Default::MakeGet()
|
|
{
|
|
if( !system->HasWriteAccess(*request->dir_tab.back()) )
|
|
{
|
|
request->status = WINIX_ERR_PERMISSION_DENIED;
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
} // namespace
|