4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Task/TaskStore.hpp"
25 #include "Task/TaskFile.hpp"
26 #include "Task/ProtectedTaskManager.hpp"
27 #include "Engine/Task/Ordered/OrderedTask.hpp"
28 #include "Components.hpp"
29 #include "OS/FileUtil.hpp"
30 #include "LocalPath.hpp"
31 #include "Language/Language.hpp"
37 class TaskFileVisitor
: public File::Visitor
40 TaskStore::ItemVector
&store
;
43 TaskFileVisitor(TaskStore::ItemVector
&_store
):
46 void Visit(const TCHAR
*path
, const TCHAR
*base_name
) {
47 // Create a TaskFile instance to determine how many
48 // tasks are inside of this task file
49 std::unique_ptr
<TaskFile
> task_file(TaskFile::Create(path
));
53 // Count the tasks in the task file
54 unsigned count
= task_file
->Count();
55 // For each task in the task file
56 for (unsigned i
= 0; i
< count
; i
++) {
57 // Copy base name of the file into task name
58 StaticString
<256> name(base_name
);
60 // If the task file holds more than one task
61 const TCHAR
*saved_name
= task_file
->GetName(i
);
62 if (saved_name
!= NULL
) {
65 } else if (count
> 1) {
66 // .. append " - Task #[n]" suffix to the task name
67 name
.AppendFormat(_T(": %s #%d"), _("Task"), i
+ 1);
70 // Add the task to the TaskStore
71 store
.emplace_back(path
, name
.empty() ? path
: name
, i
);
79 // clear entries first
80 store
.erase(store
.begin(), store
.end());
84 TaskStore::Scan(bool extra
)
89 TaskFileVisitor
tfv(store
);
90 VisitDataFiles(_T("*.tsk"), tfv
);
93 VisitDataFiles(_T("*.cup"), tfv
);
94 VisitDataFiles(_T("*.igc"), tfv
);
97 std::sort(store
.begin(), store
.end());
100 TaskStore::Item::~Item()
102 if (!filename
.empty())
107 TaskStore::Item::GetTask(const TaskBehaviour
&task_behaviour
)
113 task
= TaskFile::GetTask(filename
.c_str(), task_behaviour
,
114 &way_points
, task_index
);
123 TaskStore::GetName(unsigned index
) const
125 return store
[index
].GetName();
129 TaskStore::GetPath(unsigned index
) const
131 return store
[index
].GetPath();
135 TaskStore::GetTask(unsigned index
, const TaskBehaviour
&task_behaviour
)
137 return store
[index
].GetTask(task_behaviour
);