mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-07-14 15:47:39 +00:00
Improve game import
This commit is contained in:
parent
f40fd3e7a4
commit
c97e151e1b
14 changed files with 47 additions and 106 deletions
|
@ -4,8 +4,9 @@
|
|||
std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfNotExist){
|
||||
wxFileName file(dbpath);
|
||||
wxString ext = file.GetExt().Lower();
|
||||
bool create=createIfNotExist && !file.Exists();
|
||||
if (ext == "pgn") {
|
||||
if(createIfNotExist && !file.Exists())
|
||||
if(create)
|
||||
PGNGameBase::CreateDatabaseFile(dbpath);
|
||||
return std::shared_ptr<GameBase>(new PGNGameBase(dbpath));
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ class GameBase {
|
|||
public:
|
||||
virtual std::shared_ptr<Game> GetGame(std::uint32_t id) = 0;
|
||||
virtual void Save(std::vector<std::uint32_t> to_delete,
|
||||
std::vector<std::shared_ptr<GameBase>> databases_to_import,
|
||||
std::vector<std::string> databases_to_import,
|
||||
std::vector<std::shared_ptr<Game>> games_to_import) = 0;
|
||||
virtual std::shared_ptr<Game> GetCurrentGame() = 0;
|
||||
virtual bool NextGame() = 0;
|
||||
|
|
|
@ -79,7 +79,7 @@ std::shared_ptr<Game> PGNGameBase::GetGame(std::uint32_t id) {
|
|||
}
|
||||
|
||||
void PGNGameBase::Save(std::vector<std::uint32_t> to_delete,
|
||||
std::vector<std::shared_ptr<GameBase>> databases_to_import,
|
||||
std::vector<std::string> databases_to_import,
|
||||
std::vector<std::shared_ptr<Game>> games_to_import) {
|
||||
wxStandardPaths stdPaths = wxStandardPaths::Get();
|
||||
wxString tmp = stdPaths.GetTempDir() + "/save_pgn_tmp.pgn";
|
||||
|
@ -102,8 +102,8 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_delete,
|
|||
}
|
||||
|
||||
// Now add new games
|
||||
for (std::shared_ptr<GameBase> current : databases_to_import) {
|
||||
current->Reset();
|
||||
for(auto dbpath: databases_to_import){
|
||||
std::shared_ptr<GameBase> current=OpenDatabase(dbpath);
|
||||
while (current->NextGame()) {
|
||||
if (several) {
|
||||
new_pgn.Write("\n\n");
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
std::shared_ptr<Game> GetCurrentGame();
|
||||
std::string GetTag(std::string tag);
|
||||
void Save(std::vector<std::uint32_t> to_delete,
|
||||
std::vector<std::shared_ptr<GameBase>> databases_to_import,
|
||||
std::vector<std::string> databases_to_import,
|
||||
std::vector<std::shared_ptr<Game>> games_to_import);
|
||||
void Reset();
|
||||
void Export(std::shared_ptr<GameBase> base);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue