-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (46 loc) · 2.01 KB
/
Copy pathProgram.cs
File metadata and controls
54 lines (46 loc) · 2.01 KB
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
using Dynastream.Fit;
class Program
{
static void Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("Usage: fitfilemerger.exe path\\to\\main.fit path\\to\\secondary.fit path\\to\\merged.fit");
return;
}
string mainFile = args[0];
string secondaryFile = args[1];
string mergedFile = args[2];
using var mainFileStream = new FileStream(mainFile, FileMode.Open);
using var secondaryFileStream = new FileStream(secondaryFile, FileMode.Open);
using var destinationFileStream = new FileStream(mergedFile, FileMode.Create, FileAccess.ReadWrite);
Decode decodeMain = new();
Decode decodeSecondary = new();
Encode encode = new(ProtocolVersion.V20);
PowerCalculator powerCalculator = new();
WorkoutStepFixer workoutStepFixer = new();
// Recording power values from the secondary file
decodeSecondary.MesgEvent += (_, e) => powerCalculator.OnPowerMesg(e.mesg);
// Adding power values to the mesages from main file and passing them to the merged file
decodeMain.MesgEvent += (_, e) => powerCalculator.OnMainMesg(e.mesg);
// Fixing the workout steps in the main file to avoid problems when encoding the merged file
powerCalculator.MesgEvent += (_, e) => workoutStepFixer.OnMesg(e.mesg);
workoutStepFixer.MesgEvent += (_, e) => encode.OnMesg(e.mesg);
// Passing the mesg definitions to the main file to the merged file unaltered
decodeMain.MesgDefinitionEvent += (_, e) => encode.OnMesgDefinition(e.mesgDef);
try
{
decodeSecondary.Read(secondaryFileStream);
encode.Open(destinationFileStream);
decodeMain.Read(mainFileStream);
}
catch (FitException ex)
{
Console.WriteLine("A FitException occurred when trying to decode/encode FIT file. Message: " + ex.Message);
}
finally
{
encode?.Close();
}
}
}