12
12
using GTA . UI ;
13
13
using LemonUI ;
14
14
using LemonUI . Menus ;
15
+ using LiteDB ;
15
16
16
17
namespace ActivityGhosts
17
18
{
@@ -30,11 +31,17 @@ public class ActivityGhosts : Script
30
31
private NativeItem loadMenuItem ;
31
32
private NativeItem regroupMenuItem ;
32
33
private NativeItem deleteMenuItem ;
34
+ private readonly string gtaFolder ;
35
+ private static LiteDatabase db ;
36
+ private static ILiteCollection < ActivityFile > activityFiles ;
33
37
34
38
public ActivityGhosts ( )
35
39
{
36
40
ghosts = new List < Ghost > ( ) ;
37
41
lastTime = Environment . TickCount ;
42
+ gtaFolder = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) , "Rockstar Games" , "GTA V" ) ;
43
+ db = new LiteDatabase ( Path . Combine ( gtaFolder , "ModSettings" , "ActivityGhosts.db" ) ) ;
44
+ activityFiles = db . GetCollection < ActivityFile > ( ) ;
38
45
LoadSettings ( ) ;
39
46
CreateMenu ( ) ;
40
47
Tick += OnTick ;
@@ -85,29 +92,39 @@ private void RegroupGhosts()
85
92
86
93
private void LoadGhosts ( )
87
94
{
88
- string activitiesPath = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) + " \\ Rockstar Games \\ GTA V \\ Activities";
95
+ string activitiesPath = Path . Combine ( gtaFolder , " Activities") ;
89
96
if ( Directory . Exists ( activitiesPath ) )
90
97
{
91
- DirectoryInfo dir = new DirectoryInfo ( activitiesPath ) ;
92
- FileInfo [ ] files = dir . GetFiles ( "*.fit" ) ;
93
- foreach ( FileInfo file in files )
94
- {
95
- FitActivityDecoder fit = new FitActivityDecoder ( file . FullName ) ;
96
- List < GeoPoint > points = fit . pointList ;
97
- if ( points . Count > 1 && Game . Player . Character . Position . DistanceTo2D ( new Vector2 ( points [ 0 ] . Lat , points [ 0 ] . Long ) ) < 50f )
98
+ foreach ( var file in new DirectoryInfo ( activitiesPath ) . GetFiles ( "*.fit" ) )
99
+ if ( activityFiles . Find ( x => x . Name == file . Name ) . FirstOrDefault ( ) == null )
100
+ {
101
+ var points = new FitActivityDecoder ( file . FullName ) . pointList ;
102
+ if ( points . Count > 1 )
103
+ activityFiles . Insert ( new ActivityFile ( ) { Name = file . Name , Lat = points [ 0 ] . Lat , Long = points [ 0 ] . Long } ) ;
104
+ }
105
+ foreach ( var file in activityFiles . FindAll ( ) )
106
+ if ( Game . Player . Character . Position . DistanceTo2D ( new Vector2 ( file . Lat , file . Long ) ) < 50f )
98
107
{
99
- int offset = ghosts . Count / 2 + 1 ;
100
- if ( ghosts . Count % 2 == 0 )
101
- offset *= - 1 ;
102
- points [ 0 ] . Lat += offset ;
103
- float h = Game . Player . Character . Heading ;
104
- if ( ( h > 90f && h < 180f ) || ( h > 270f && h < 360f ) )
105
- points [ 0 ] . Long -= offset ;
108
+ string fullName = Path . Combine ( activitiesPath , file . Name ) ;
109
+ if ( System . IO . File . Exists ( fullName ) )
110
+ {
111
+ var fit = new FitActivityDecoder ( fullName ) ;
112
+ if ( fit . pointList . Count > 1 )
113
+ {
114
+ int offset = ghosts . Count / 2 + 1 ;
115
+ if ( ghosts . Count % 2 == 0 )
116
+ offset *= - 1 ;
117
+ float h = Game . Player . Character . Heading ;
118
+ if ( ( h > 45f && h < 135f ) || ( h > 225f && h < 315f ) )
119
+ fit . pointList [ 0 ] . Long += offset ;
120
+ else
121
+ fit . pointList [ 0 ] . Lat += offset ;
122
+ ghosts . Add ( new Ghost ( fit . pointList , fit . sport , fit . startTime ) ) ;
123
+ }
124
+ }
106
125
else
107
- points [ 0 ] . Long += offset ;
108
- ghosts . Add ( new Ghost ( points , fit . sport , fit . startTime ) ) ;
126
+ activityFiles . Delete ( file . Id ) ;
109
127
}
110
- }
111
128
if ( ghosts . Count > 0 )
112
129
{
113
130
start = World . CreateBlip ( Game . Player . Character . Position ) ;
@@ -553,4 +570,12 @@ private double DegToRad(float angleDeg)
553
570
return angleDeg * Math . PI / 180.0f ;
554
571
}
555
572
}
573
+
574
+ public class ActivityFile
575
+ {
576
+ public int Id { get ; set ; }
577
+ public string Name { get ; set ; }
578
+ public float Lat { get ; set ; }
579
+ public float Long { get ; set ; }
580
+ }
556
581
}
0 commit comments