2008-12-10 05:42:49 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-02-24 01:19:47 +01:00
|
|
|
* Copyright (c) 2008-2021, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-12-10 05:42:49 +01:00
|
|
|
*/
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
#ifndef headerfile_winix_core_dirs
|
|
|
|
#define headerfile_winix_core_dirs
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include "dircontainer.h"
|
2010-09-18 02:51:12 +02:00
|
|
|
#include "db/db.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "request.h"
|
2021-02-24 01:19:47 +01:00
|
|
|
#include "models/item.h"
|
2021-06-16 18:07:44 +02:00
|
|
|
#include "winixmodeldeprecated.h"
|
2018-11-21 12:03:53 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
2018-11-21 12:03:53 +01:00
|
|
|
class Notify;
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
// !! IMPROVE ME
|
2009-11-17 02:04:01 +01:00
|
|
|
// we do not support '..' in a path (for simplicity and security reasons)
|
2014-02-12 17:30:49 +01:00
|
|
|
// (we will support '..' in the future)
|
2009-11-17 02:04:01 +01:00
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
class Dirs : public WinixModelDeprecated
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
void ReadDirs();
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
void SetCur(Cur * pcur);
|
2010-08-10 18:12:50 +02:00
|
|
|
void SetDb(Db * pdb);
|
2010-12-02 02:02:02 +01:00
|
|
|
void SetNotify(Notify * pnotify);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
void set_dependency(WinixModelDeprecated * winix_model);
|
2018-11-21 23:53:24 +01:00
|
|
|
|
2009-11-17 02:04:01 +01:00
|
|
|
// these methods return false if there is no such a dir
|
|
|
|
bool IsDir(long dir_id);
|
2010-10-19 02:31:20 +02:00
|
|
|
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()
|
2011-01-05 22:24:11 +01:00
|
|
|
bool MakePath(long dir_id, std::wstring & path, bool clear_path = true);
|
2011-08-02 02:10:45 +02:00
|
|
|
void MakePath(const std::vector<Item*> dir_tab, std::wstring & path, bool clear_path = true);
|
2010-03-15 02:47:26 +01:00
|
|
|
bool ChangeParent(long dir_id, long new_parent_id);
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2010-03-15 02:47:26 +01:00
|
|
|
bool HasParent(long dir_id, long parent_id);
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2010-03-15 18:09:45 +01:00
|
|
|
bool DelDir(long dir_id);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2012-01-25 00:03:36 +01:00
|
|
|
// if returns true then out_dir_tab is not empty
|
2011-01-05 22:24:11 +01:00
|
|
|
bool CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab);
|
|
|
|
|
|
|
|
void LogDir(const std::vector<Item*> & dir_tab);
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
int AnalyzePath(const std::wstring & path, long & dir_id, std::wstring & dir, std::wstring & file);
|
2011-01-05 22:24:11 +01:00
|
|
|
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
|
|
|
std::vector<Item*> & out_dir_tab, std::wstring & out_item);
|
2010-11-21 01:19:17 +01:00
|
|
|
static void SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2011-01-24 00:23:24 +01:00
|
|
|
DirContainer::ParentIterator FindFirstChild(long parent_id);
|
2011-01-05 22:24:11 +01:00
|
|
|
DirContainer::ParentIterator NextChild(DirContainer::ParentIterator i);
|
2011-01-24 00:23:24 +01:00
|
|
|
DirContainer::ParentIterator ParentEnd(); // !! pozostalo do zamiany na child
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-03-15 02:47:26 +01:00
|
|
|
|
2009-11-17 02:04:01 +01:00
|
|
|
// these methods return null if there is no such a dir
|
2010-08-10 18:12:50 +02:00
|
|
|
// !! zmienic nazwy wskazujace ze operujemy tylko na lokalnej tablicy
|
2008-12-30 02:05:03 +01:00
|
|
|
Item * GetRootDir();
|
2009-11-16 00:55:11 +01:00
|
|
|
Item * GetEtcDir();
|
2010-11-04 17:46:19 +01:00
|
|
|
Item * GetVarDir();
|
2012-09-14 01:12:48 +02:00
|
|
|
|
|
|
|
Item * GetDir(const wchar_t * name, long parent);
|
2010-11-21 01:19:17 +01:00
|
|
|
Item * GetDir(const std::wstring & name, long parent);
|
2012-09-14 01:12:48 +02:00
|
|
|
Item * GetDir(const wchar_t * path);
|
2010-11-21 01:19:17 +01:00
|
|
|
Item * GetDir(const std::wstring & path);
|
2008-12-30 02:05:03 +01:00
|
|
|
Item * GetDir(long id);
|
2009-04-20 00:13:21 +02:00
|
|
|
Item * AddDir(const Item & item);
|
2008-12-31 19:28:12 +01:00
|
|
|
|
2021-06-18 19:18:13 +02:00
|
|
|
const Item * GetDir(long id) const;
|
|
|
|
|
2009-02-06 14:12:03 +01:00
|
|
|
void CheckRootDir();
|
|
|
|
|
2010-11-04 17:46:19 +01:00
|
|
|
Item * CreateVarDir();
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-11-04 17:46:19 +01:00
|
|
|
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
|
2021-02-24 01:19:47 +01:00
|
|
|
bool AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
2009-02-06 14:12:03 +01:00
|
|
|
|
2011-06-15 01:45:42 +02:00
|
|
|
// returns how many levels of directories there are
|
|
|
|
// "/" -> 0 (root dir)
|
|
|
|
// "/abc" -> 1
|
|
|
|
// "/abc/def" -> 2
|
|
|
|
size_t DirLevel(long id);
|
|
|
|
|
2011-06-21 23:24:49 +02:00
|
|
|
// checking if child_id is really a child of parent_id
|
|
|
|
bool IsChild(long parent_id, long child_id);
|
|
|
|
|
2009-02-06 14:12:03 +01:00
|
|
|
private:
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
Cur * cur;
|
|
|
|
Db * db;
|
2010-12-02 02:02:02 +01:00
|
|
|
Notify * notify;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
DirContainer dir_tab;
|
2011-01-05 22:24:11 +01:00
|
|
|
std::wstring temp_path;
|
|
|
|
std::wstring temp_link_to;
|
2009-02-06 14:12:03 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
|
2012-01-25 00:03:36 +01:00
|
|
|
bool AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to, size_t & i);
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring analyze_temp;
|
2011-07-14 01:14:10 +02:00
|
|
|
std::wstring get_dir_temp;
|
2010-03-15 02:47:26 +01:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
void CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out);
|
|
|
|
int FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item);
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool ExtractName(const wchar_t * & s, std::wstring & name);
|
2010-08-10 18:12:50 +02:00
|
|
|
bool HasReadExecAccessForRoot(const Item & item);
|
2009-02-06 14:12:03 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
} // namespace Winix
|
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
#endif
|