165 lines
2.7 KiB
C++
Executable File
165 lines
2.7 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010-2012, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "threadinfo.h"
|
|
#include "core/plugin.h"
|
|
#include "pluginmsg.h"
|
|
|
|
|
|
|
|
namespace Thread
|
|
{
|
|
|
|
void ThreadInfo::SetDb(Db * pdb)
|
|
{
|
|
db = pdb;
|
|
}
|
|
|
|
|
|
void ThreadInfo::SetTDb(TDb * ptdb)
|
|
{
|
|
tdb = ptdb;
|
|
}
|
|
|
|
|
|
void ThreadInfo::SetSystem(System * psystem)
|
|
{
|
|
system = psystem;
|
|
}
|
|
|
|
|
|
void ThreadInfo::Clear()
|
|
{
|
|
item_tab.clear();
|
|
thread_tab.clear();
|
|
item_sort_tab.clear();
|
|
}
|
|
|
|
|
|
|
|
Item * ThreadInfo::FindThreadDir()
|
|
{
|
|
Item * plugin_dir = 0;
|
|
plugin.Call(WINIX_PL_THREAD_SEARCH_THREAD_DIR, &plugin_dir);
|
|
|
|
if( plugin_dir )
|
|
return plugin_dir;
|
|
|
|
const std::wstring & dir_str = system->mounts.pmount->FirstArg(mount_par_thread_dir);
|
|
|
|
if( dir_str.empty() )
|
|
return 0;
|
|
|
|
int res = system->FollowAllLinks(dir_str, out_dir_tab, out_item);
|
|
|
|
if( res != 0 )
|
|
return 0;
|
|
|
|
return out_dir_tab.back();
|
|
}
|
|
|
|
|
|
|
|
void ThreadInfo::RemoveThread(long file_id)
|
|
{
|
|
if( tdb->GetAnswers(file_id, remove_answer_id_tab) == WINIX_ERR_OK )
|
|
{
|
|
for(size_t i=0 ; i<remove_answer_id_tab.size() ; ++i)
|
|
db->DelFileById(remove_answer_id_tab[i]);
|
|
}
|
|
|
|
tdb->RemoveThread(file_id);
|
|
}
|
|
|
|
|
|
|
|
void ThreadInfo::RemoveThreadAnswer(long answer_id)
|
|
{
|
|
tdb->RemoveAnswer(answer_id);
|
|
}
|
|
|
|
|
|
|
|
void ThreadInfo::RepairAnswer(long answer_id)
|
|
{
|
|
iq.Clear();
|
|
iq.SetAll(false, false);
|
|
iq.WhereId(answer_id);
|
|
iq.WhereType(Item::file); // !! moze w przyszlosci pozwolic takze na symlinki?
|
|
|
|
if( db->GetItem(repair_item, iq) == WINIX_ERR_NO_ITEM )
|
|
{
|
|
log << log3 << "ThreadInfo: there is no a file for thread answer_id: " << answer_id << logend;
|
|
tdb->RemoveAnswerOnly(answer_id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ThreadInfo::RepairAnswers(long file_id)
|
|
{
|
|
tdb->GetAnswers(file_id, repair_answer_tab);
|
|
|
|
for(size_t i=0 ; i<repair_answer_tab.size() ; ++i)
|
|
RepairAnswer(repair_answer_tab[i]);
|
|
}
|
|
|
|
|
|
void ThreadInfo::Repair(long file_id)
|
|
{
|
|
iq.Clear();
|
|
iq.SetAll(false, false);
|
|
iq.WhereId(file_id);
|
|
iq.WhereType(Item::file); // !! moze w przyszlosci pozwolic takze na symlinki?
|
|
|
|
if( db->GetItem(repair_item, iq) == WINIX_ERR_NO_ITEM )
|
|
{
|
|
log << log3 << "ThreadInfo: there is no a file for thread file_id: " << file_id << logend;
|
|
tdb->RemoveThread(file_id);
|
|
}
|
|
else
|
|
{
|
|
RepairAnswers(file_id);
|
|
tdb->RecalcThread(file_id);
|
|
}
|
|
}
|
|
|
|
|
|
void ThreadInfo::Repair()
|
|
{
|
|
tdb->GetAllThreadsId(repair_id_tab);
|
|
|
|
for(size_t i=0 ; i<repair_id_tab.size() ; ++i)
|
|
Repair(repair_id_tab[i]);
|
|
}
|
|
|
|
|
|
|
|
void ThreadInfo::MakeRedirectIfPossible(const Item & item)
|
|
{
|
|
PluginRes res = plugin.Call(WINIX_PL_THREAD_CAN_MAKE_REDIRECT);
|
|
|
|
if( res.res_false > 0 )
|
|
{
|
|
log << log4 << "Thread: redirect prevented" << logend;
|
|
return;
|
|
}
|
|
|
|
system->RedirectTo(item);
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|