1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*-
// ***** BEGIN LICENSE BLOCK *****
////////////////////////////////////////////////////////////////////
// Copyright (c) 2011-2013 RALOVICH, Kristóf //
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
// version 2 as published by the Free Software Foundation. //
// //
////////////////////////////////////////////////////////////////////
// ***** END LICENSE BLOCK *****
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include "AntMessage.hpp"
#include "FIT.hpp"
#include "common.hpp"
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
namespace po = boost::program_options;
namespace fs = boost::filesystem;
using namespace std;
const
std::vector<fs::path>
find_files(const fs::path & dir_path, // in this directory,
const std::string & ext // search for this extension,
)
{
std::vector<fs::path> paths;
if ( !fs::exists( dir_path ) ) return paths;
fs::directory_iterator end_itr; // default construction yields past-the-end
for ( fs::directory_iterator itr( dir_path );
itr != end_itr;
++itr )
{
if ( fs::is_directory(itr->status()) )
{
std::vector<fs::path> paths2(find_files( itr->path(), ext) );
paths.insert(paths.end(), paths2.begin(), paths2.end());
}
else if ( fs::extension(*itr) == ext ) // see below
{
paths.push_back(*itr);
}
}
return paths;
}
int
main(int argc, char** argv)
{
// Declare the supported options.
std::string fitFolder;
std::string fitRootFile;
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("fitFolder,F", po::value<std::string>(&fitFolder), "Folder with FIT files")
("decode-fit-root,D", po::value<std::string>(&fitRootFile), "FIT file, encoding the root directory contents on a device")
;
std::vector<const char*> args(argv, argv+argc);
po::variables_map vm;
try
{
//po::parsed_options parsed = po::parse_command_line(argc, argv, desc);
po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).run();
po::store(parsed, vm);
po::notify(vm);
}
catch(po::error& error)
{
cerr << error.what() << "\n";
cerr << desc << "\n";
return EXIT_FAILURE;
}
if(vm.count("help")
|| (fitFolder.empty() && fitRootFile.empty()))
{
cout << desc << "\n";
return EXIT_SUCCESS;
}
if(!fitRootFile.empty())
{
ZeroFileContent zfc;
FIT fit;
vector<uchar> v(readFile(fitRootFile.c_str()));
if(fit.parseZeroFile(v, zfc))
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
if(!fs::is_directory(fs::path(fitFolder)))
{
LOG_VAR(fitFolder);
CHECK_RETURN_RV_LOG_OK(fs::is_directory(fs::path(fitFolder)), EXIT_FAILURE);
}
std::vector<fs::path> fitFiles(find_files(fs::path(fitFolder), ".fit"));
for (size_t i = 0; i < fitFiles.size(); i++)
{
const std::string in(fitFiles[i].string());
#if BOOST_VERSION==104300
const std::string out(fitFiles[i].parent_path().string()+"//"+fitFiles[i].stem()+".gpx");
#else
const std::string out(fitFiles[i].parent_path().string()+"//"+fitFiles[i].stem().string()+".gpx");
#endif
LOG_VAR2(in, out);
GPX gpx;
FIT fit;
vector<uchar> v(readFile(in.c_str()));
if(fit.parse(v, gpx))
gpx.writeToFile(out);
}
return EXIT_SUCCESS;
}
|