added: Patterns class (in templates)
ezc patterns are managed by this class added: some work in groupitem plugin (not finished yet) changed: ConfParser can read a string from memory now (need some testing yet) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@757 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
203
plugins/groupitem/groupinfo.cpp
Executable file
203
plugins/groupitem/groupinfo.cpp
Executable file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "groupinfo.h"
|
||||
#include "core/log.h"
|
||||
#include "core/system.h"
|
||||
|
||||
|
||||
|
||||
namespace GroupItem
|
||||
{
|
||||
|
||||
|
||||
GroupInfo::GroupInfo()
|
||||
{
|
||||
mount_par_group_conf = -1;
|
||||
mount_par_group_lang_conf = -1;
|
||||
}
|
||||
|
||||
|
||||
void GroupInfo::SetSystem(System * psystem)
|
||||
{
|
||||
system = psystem;
|
||||
}
|
||||
|
||||
|
||||
Groups * GroupInfo::FindGroups(long dir_id)
|
||||
{
|
||||
GroupsWrap::iterator i = groups_wrap.find(dir_id);
|
||||
|
||||
if( i == groups_wrap.end() )
|
||||
return 0;
|
||||
|
||||
return &(i->second.groups);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool GroupInfo::ParseGroups(const std::wstring & str, Groups & groups)
|
||||
{
|
||||
groups.Clear();
|
||||
|
||||
if( conf_parser.ParseString(str) == ConfParser::ok )
|
||||
{
|
||||
ConfParser::Table::iterator i;
|
||||
|
||||
for(i=conf_parser.table.begin() ; i!=conf_parser.table.end() ; ++i)
|
||||
{
|
||||
groups.AddGroup();
|
||||
log << log1 << "stworzylem nowa grupe" << logend;
|
||||
|
||||
for(size_t a=0 ; a<i->second.size() ; ++a)
|
||||
{
|
||||
groups.AddPath(i->second[a]);
|
||||
log << log1 << " dodalem sciezke: " << i->second[a] << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return conf_parser.status == ConfParser::ok;
|
||||
}
|
||||
|
||||
|
||||
void GroupInfo::MarkAllGroupsToDelete()
|
||||
{
|
||||
GroupsWrap::iterator i = groups_wrap.begin();
|
||||
|
||||
for( ; i != groups_wrap.end() ; ++i)
|
||||
i->second.to_delete = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void GroupInfo::DeleteAllMarkedGroups()
|
||||
{
|
||||
GroupsWrap::iterator inext;
|
||||
GroupsWrap::iterator i = groups_wrap.begin();
|
||||
|
||||
while( i != groups_wrap.end() )
|
||||
{
|
||||
inext = i;
|
||||
++inext;
|
||||
|
||||
if( i->second.to_delete )
|
||||
{
|
||||
log << log3 << "GroupItem: deleting group for dir id: " << i->first << logend;
|
||||
groups_wrap.erase(i);
|
||||
}
|
||||
|
||||
i = inext;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool GroupInfo::GetConfContent(const std::wstring & path)
|
||||
{
|
||||
int status = system->FollowAllLinks(path, config_dir_tab, config_file, false, false, false);
|
||||
|
||||
if( status != 1 )
|
||||
{
|
||||
log << log1 << "GroupItem: problem with reading a config file: " << path << ", status: " << status << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// if skip_existing_configs is true then only new config files will be parsed
|
||||
void GroupInfo::ReadGroupsConf(Mounts & mounts, bool skip_existing_configs)
|
||||
{
|
||||
Mounts::MountTab::const_iterator i;
|
||||
const Mounts::MountTab * mtab = mounts.GetMountTab();
|
||||
|
||||
// loop through all mount points
|
||||
for(i=mtab->begin() ; i!=mtab->end() ; ++i)
|
||||
{
|
||||
const Mount & mount = i->second;
|
||||
|
||||
if( mount.param[mount_par_group_conf].defined &&
|
||||
mount.param[mount_par_group_conf].arg.size() == 1 )
|
||||
{
|
||||
const std::wstring & file_name = mount.param[mount_par_group_conf].arg[0];
|
||||
GroupsWrap::iterator c = groups_wrap.find(mount.dir_id);
|
||||
bool exists = (c != groups_wrap.end() && c->second.file_name == file_name);
|
||||
|
||||
if( exists )
|
||||
c->second.to_delete = false;
|
||||
|
||||
if( !(skip_existing_configs && exists) )
|
||||
{
|
||||
if( GetConfContent(file_name) )
|
||||
{
|
||||
log << log3 << "GroupItem: parsing conf file: " << config_file.url << logend;
|
||||
groups_wrap[mount.dir_id].file_name = file_name;
|
||||
|
||||
if( !ParseGroups(config_file.content, groups_wrap[mount.dir_id].groups) )
|
||||
groups_wrap[mount.dir_id].to_delete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( exists )
|
||||
c->second.to_delete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if skip_existing_configs is true then only new config files will be parsed
|
||||
void GroupInfo::ReadGroupsConfigs(bool skip_existing_configs)
|
||||
{
|
||||
MarkAllGroupsToDelete();
|
||||
ReadGroupsConf(system->mounts, skip_existing_configs);
|
||||
DeleteAllMarkedGroups();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GroupInfo::PrintGroups()
|
||||
{
|
||||
GroupsWrap::iterator i = groups_wrap.begin();
|
||||
|
||||
for( ; i != groups_wrap.end() ; ++i)
|
||||
{
|
||||
log << "grupy dla dir_id: " << i->first << logend;
|
||||
|
||||
Groups & g = i->second.groups;
|
||||
|
||||
log << "rozmiar: " << g.Size() << logend;
|
||||
|
||||
for(size_t a=0 ; a<g.Size() ; ++a )
|
||||
{
|
||||
log << "grupa: " << a << logend;
|
||||
log << "sciezek: " << g.GroupSize(a) << logend;
|
||||
|
||||
for(size_t x=0 ; x<g.GroupSize(a) ; ++x)
|
||||
{
|
||||
log << " " << g.GroupPath(a, x) << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user