-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
145 lines (134 loc) · 5.85 KB
/
Program.cs
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
134
135
136
137
138
139
140
141
142
143
144
145
/*
* This file is part of the BandSensorLogToTcx distribution (https://github.com/OverallLine5/BandSensorLogToTcx).
* Copyright (c) 2021 Marcus Lösel (OverallLine5).
*
* 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 3.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BandSensorLogToTcx
{
//=========================================================================================================
class Program
//=========================================================================================================
{
//------------------------------------------------------------------------------------------------------
static void Main( string[] args )
//------------------------------------------------------------------------------------------------------
{
string strSensorLogPath = ".";
string strWorkoutPath = ".";
Console.WriteLine( System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " (C) 2021 Marcus Lösel" );
Console.WriteLine();
if( args.Length <= 1 )
{
Console.WriteLine( "Usage: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " <path containing sensor log files> <path to store exported workouts>" );
return;
}
else
{
strSensorLogPath = args[0];
strWorkoutPath = args[1];
if( !Directory.Exists( strSensorLogPath ) )
{
Console.WriteLine( strSensorLogPath + " does not exist." );
return;
}
if( !Directory.Exists( strWorkoutPath ) )
{
Console.WriteLine( strWorkoutPath + " does not exist." );
return;
}
}
SensorLog sensorLog = new SensorLog();
try
{
Dictionary<DateTime, string> dictFiles = new Dictionary<DateTime, string>();
var dataFiles = Directory.EnumerateFiles( strSensorLogPath, "*.*", SearchOption.TopDirectoryOnly );
string strFileName;
DateTime dtFile = System.DateTime.MinValue;
foreach( string currentFile in dataFiles )
{
using( var fileStream = new FileStream( currentFile, FileMode.Open, FileAccess.Read, FileShare.Read ) )
{
if( SensorLog.IsSensorLog( fileStream, out dtFile ) )
dictFiles.Add( dtFile, currentFile );
}
}
var dateTimesAscending = dictFiles.Keys.OrderBy( d => d );
foreach( var dtCurrent in dateTimesAscending )
{
strFileName = dictFiles[dtCurrent];
using( var fileStream = new FileStream( strFileName, FileMode.Open, FileAccess.Read, FileShare.Read ) )
{
sensorLog.Read( fileStream );
}
}
if( dictFiles.Count == 0 )
{
Console.WriteLine( strSensorLogPath + " does not contain any sensor log files." );
return;
}
}
catch( Exception ex )
{
Console.WriteLine( "Unable to read sensor log files: " + ex.Message );
return;
}
try
{
// create workouts
if( sensorLog.Sequences.Count > 0 )
{
var workouts = sensorLog.CreateWorkouts();
var iCount = 0;
if( workouts.Count > 0 )
{
foreach( var workout in workouts )
{
if( workout.TrackPoints.Count > 0 )
{
var pathTcx = Path.Combine( strWorkoutPath, workout.Filename );
if( !File.Exists( pathTcx ) )
{
using( StreamWriter outputFile = new StreamWriter( pathTcx ) )
{
outputFile.Write( workout.TCXBuffer );
Console.WriteLine( "Exporting " + workout.Filename );
iCount++;
}
}
else
Console.WriteLine( workout.Filename + " already exists." );
}
}
Console.WriteLine();
if( iCount > 0 )
Console.WriteLine( "Successfully exported " + iCount + " workouts." );
else
Console.WriteLine( "No workout was exported." );
}
}
}
catch( Exception ex )
{
Console.WriteLine( "Unable to write workout files: " + ex.Message );
return;
}
}
}
}