grive2/libgrive/src/base/State.hh

89 lines
2.0 KiB
C++
Raw Normal View History

2012-05-16 18:35:22 +04:00
/*
grive: an GPL program to sync a local directory with Google Drive
Copyright (C) 2012 Wan Wai Ho
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#pragma once
#include "ResourceTree.hh"
#include "util/DateTime.hh"
2012-05-16 20:52:17 +04:00
#include "util/FileSystem.hh"
#include "json/Val.hh"
2012-05-16 18:35:22 +04:00
2012-05-16 20:52:17 +04:00
#include <memory>
2015-09-25 13:01:26 +03:00
#include <boost/regex.hpp>
2012-05-16 18:35:22 +04:00
namespace gr {
class Entry ;
class Syncer ;
2012-05-19 11:41:21 +04:00
class Resource ;
2012-05-16 18:35:22 +04:00
class State
{
2012-05-19 13:14:04 +04:00
public :
typedef ResourceTree::iterator iterator ;
2012-05-19 13:14:04 +04:00
2012-05-16 18:35:22 +04:00
public :
explicit State( const fs::path& root, const Val& options ) ;
~State() ;
2012-05-16 18:35:22 +04:00
2012-05-19 21:44:46 +04:00
void FromLocal( const fs::path& p ) ;
void FromRemote( const Entry& e ) ;
2012-05-17 20:37:11 +04:00
void ResolveEntry() ;
void Read() ;
void Write() ;
2012-05-16 18:35:22 +04:00
Resource* FindByHref( const std::string& href ) ;
Resource* FindByID( const std::string& id ) ;
2012-05-17 20:37:11 +04:00
void Sync( Syncer *syncer, const Val& options ) ;
2012-05-19 13:14:04 +04:00
iterator begin() ;
iterator end() ;
2012-06-03 19:58:28 +04:00
long ChangeStamp() const ;
void ChangeStamp( long cstamp ) ;
2012-05-17 20:37:11 +04:00
private :
bool ParseIgnoreFile( const char* buffer, int size ) ;
void FromLocal( const fs::path& p, Resource *folder, Val& tree ) ;
2012-06-10 17:03:32 +04:00
void FromChange( const Entry& e ) ;
2012-05-17 20:37:11 +04:00
bool Update( const Entry& e ) ;
std::size_t TryResolveEntry() ;
2015-09-25 13:01:26 +03:00
bool IsIgnore( const std::string& filename ) ;
2012-05-16 18:35:22 +04:00
private :
fs::path m_root ;
ResourceTree m_res ;
2014-07-23 14:47:16 +04:00
int m_cstamp ;
std::string m_ign ;
boost::regex m_ign_re ;
Val m_st ;
bool m_force ;
bool m_ign_changed ;
2012-05-18 04:52:11 +04:00
std::list<Entry> m_unresolved ;
2012-05-16 18:35:22 +04:00
} ;
} // end of namespace gr