Skip to content

Commit 671cb02

Browse files
committed
Syncing basics in place. Thanks Zingabopp!
1 parent f7af76b commit 671cb02

22 files changed

+879
-19
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "beatsaber-hook"]
55
path = beatsaber-hook
66
url = https://github.com/emulamer/beatsaber-hook
7+
[submodule "SyncSaberService"]
8+
path = SyncSaberService
9+
url = https://github.com/Zingabopp/SyncSaberService/

BeatOn.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assplorer", "QuestomAssets\
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeatmapAssetMaker", "QuestomAssets\BeatMapAssetMaker\BeatmapAssetMaker.csproj", "{DB4F8C58-2479-4C96-85C9-F06D2DA36ECB}"
1919
EndProject
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeedReader", "SyncSaberService\FeedReader\FeedReader.csproj", "{D846C41A-95F1-468B-8B29-738CF3D92C3E}"
21+
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2224
Debug|Any CPU = Debug|Any CPU
@@ -213,6 +215,30 @@ Global
213215
{DB4F8C58-2479-4C96-85C9-F06D2DA36ECB}.Release|x64.Build.0 = Release|Any CPU
214216
{DB4F8C58-2479-4C96-85C9-F06D2DA36ECB}.Release|x86.ActiveCfg = Release|Any CPU
215217
{DB4F8C58-2479-4C96-85C9-F06D2DA36ECB}.Release|x86.Build.0 = Release|Any CPU
218+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
219+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
220+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Debug|x64.ActiveCfg = Debug|Any CPU
221+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Debug|x64.Build.0 = Debug|Any CPU
222+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Debug|x86.ActiveCfg = Debug|Any CPU
223+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Debug|x86.Build.0 = Debug|Any CPU
224+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Emulator Debug|Any CPU.ActiveCfg = Debug|Any CPU
225+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Emulator Debug|Any CPU.Build.0 = Debug|Any CPU
226+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Emulator Debug|x64.ActiveCfg = Debug|Any CPU
227+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Emulator Debug|x64.Build.0 = Debug|Any CPU
228+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Emulator Debug|x86.ActiveCfg = Debug|Any CPU
229+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Emulator Debug|x86.Build.0 = Debug|Any CPU
230+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Profiler|Any CPU.ActiveCfg = Debug|Any CPU
231+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Profiler|Any CPU.Build.0 = Debug|Any CPU
232+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Profiler|x64.ActiveCfg = Debug|Any CPU
233+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Profiler|x64.Build.0 = Debug|Any CPU
234+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Profiler|x86.ActiveCfg = Debug|Any CPU
235+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Profiler|x86.Build.0 = Debug|Any CPU
236+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
237+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Release|Any CPU.Build.0 = Release|Any CPU
238+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Release|x64.ActiveCfg = Release|Any CPU
239+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Release|x64.Build.0 = Release|Any CPU
240+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Release|x86.ActiveCfg = Release|Any CPU
241+
{D846C41A-95F1-468B-8B29-738CF3D92C3E}.Release|x86.Build.0 = Release|Any CPU
216242
EndGlobalSection
217243
GlobalSection(SolutionProperties) = preSolution
218244
HideSolutionNode = FALSE

BeatOn/BeatOn.csproj

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<Compile Include="BeatOnService.cs" />
111111
<Compile Include="BeatOnServiceTransciever.cs" />
112112
<Compile Include="BeatOnUtils.cs" />
113+
<Compile Include="BeatSaverUtils.cs" />
113114
<Compile Include="BPList.cs" />
114115
<Compile Include="ClientModels\BeatOnConfig.cs" />
115116
<Compile Include="ClientModels\ClientChangeColor.cs" />
@@ -125,6 +126,8 @@
125126
<Compile Include="ClientModels\ClientDeleteSong.cs" />
126127
<Compile Include="ClientModels\ClientMoveSongToPlaylist.cs" />
127128
<Compile Include="ClientModels\ActionResponse.cs" />
129+
<Compile Include="ClientModels\ClientSyncSaber.cs" />
130+
<Compile Include="ClientModels\ClientUpdateSyncFeedConfig.cs" />
128131
<Compile Include="ClientModels\HostConfigChangeEvent.cs" />
129132
<Compile Include="ClientModels\HostDownload.cs" />
130133
<Compile Include="ClientModels\HostOp.cs" />
@@ -153,8 +156,12 @@
153156
<Compile Include="Core\MessageHandlers\ClientMoveSongToPlaylistHandler.cs" />
154157
<Compile Include="Core\MessageHandlers\ClientAutoCreatePlaylistsHandler.cs" />
155158
<Compile Include="Core\MessageHandlers\ClientSortPlaylistHandler.cs" />
159+
<Compile Include="Core\MessageHandlers\ClientUpdateSyncFeedConfigHandler.cs" />
160+
<Compile Include="Core\MessageHandlers\ClientSyncSaberHandler.cs" />
156161
<Compile Include="Core\RequestHandlers\GetConfig.cs" />
157162
<Compile Include="Core\RequestHandlers\GetModCover.cs" />
163+
<Compile Include="Core\RequestHandlers\PostSyncSync.cs" />
164+
<Compile Include="Core\RequestHandlers\GetSyncConfig.cs" />
158165
<Compile Include="Core\RequestHandlers\PostExit.cs" />
159166
<Compile Include="Core\RequestHandlers\PostConfigRestore.cs" />
160167
<Compile Include="Core\RequestHandlers\PostPackageAction.cs" />
@@ -202,6 +209,9 @@
202209
<Compile Include="Delegates.cs" />
203210
<Compile Include="SimpleRouter.cs" />
204211
<Compile Include="StatusUpdateLogSink.cs" />
212+
<Compile Include="SyncConfig.cs" />
213+
<Compile Include="SyncException.cs" />
214+
<Compile Include="SyncManager.cs" />
205215
<Compile Include="ToastInjectorWebViewClient.cs" />
206216
<Compile Include="WebServer.cs" />
207217
</ItemGroup>
@@ -269,6 +279,10 @@
269279
<Project>{e6acae1d-f608-4d45-a73c-3d2ebc22d7d4}</Project>
270280
<Name>QuestomAssets</Name>
271281
</ProjectReference>
282+
<ProjectReference Include="..\SyncSaberService\FeedReader\FeedReader.csproj">
283+
<Project>{d846c41a-95f1-468b-8b29-738cf3d92c3e}</Project>
284+
<Name>FeedReader</Name>
285+
</ProjectReference>
272286
</ItemGroup>
273287
<ItemGroup>
274288
<AndroidResource Include="Resources\xml\provider_paths.xml" />
@@ -353,13 +367,13 @@
353367
<AndroidAsset Include="Assets\www\polyfills-es5.27d81060418231ff91d8.js" />
354368
</ItemGroup>
355369
<ItemGroup>
356-
<AndroidAsset Include="Assets\www\styles.897db6043558b11e7565.css" />
370+
<AndroidAsset Include="Assets\www\main-es2015.abc10ad845673db52760.js" />
357371
</ItemGroup>
358372
<ItemGroup>
359-
<AndroidAsset Include="Assets\www\main-es2015.ac3c69c65ac08ba69b42.js" />
373+
<AndroidAsset Include="Assets\www\main-es5.241a1a357dbc0a48a4a8.js" />
360374
</ItemGroup>
361375
<ItemGroup>
362-
<AndroidAsset Include="Assets\www\main-es5.1d14f310f8a0dd394bb6.js" />
376+
<AndroidAsset Include="Assets\www\styles.00f63c1921c850968e3f.css" />
363377
</ItemGroup>
364378
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
365379
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

BeatOn/BeatSaverUtils.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Text;
6+
7+
using Android.App;
8+
using Android.Content;
9+
using Android.OS;
10+
using Android.Runtime;
11+
using Android.Views;
12+
using Android.Widget;
13+
using Newtonsoft.Json.Linq;
14+
using QuestomAssets;
15+
16+
namespace BeatOn
17+
{
18+
public static class BeatSaverUtils
19+
{
20+
public static string GetDownloadUrl(string apiURL)
21+
{
22+
WebClient client = new WebClient();
23+
try
24+
{
25+
var bsaver = client.DownloadString(apiURL);
26+
JToken jt = JToken.Parse(bsaver);
27+
return jt.Value<string>("downloadURL");
28+
}
29+
catch (WebException wex)
30+
{
31+
Log.LogMsg($"BeatSaver failed to get info for {apiURL}, status {wex.Status}");
32+
return null;
33+
}
34+
}
35+
}
36+
}

BeatOn/ClientModels/BeatOnConfig.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ public BeatSaberQuestomConfig Config {
6161
}
6262
}
6363

64+
private SyncConfig _syncConfig;
65+
public SyncConfig SyncConfig
66+
{
67+
get
68+
{
69+
return _syncConfig;
70+
}
71+
set
72+
{
73+
_syncConfig = value;
74+
PropChanged(nameof(SyncConfig));
75+
}
76+
}
77+
6478
private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e)
6579
{
6680
PropChanged(nameof(Config));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
using Android.App;
7+
using Android.Content;
8+
using Android.OS;
9+
using Android.Runtime;
10+
using Android.Views;
11+
using Android.Widget;
12+
13+
namespace BeatOn.ClientModels
14+
{
15+
public class ClientSyncSaber : MessageBase
16+
{
17+
public override MessageType Type => MessageType.SyncSaber;
18+
19+
public Guid? SyncOnlyID { get; set; }
20+
21+
}
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
using Android.App;
7+
using Android.Content;
8+
using Android.OS;
9+
using Android.Runtime;
10+
using Android.Views;
11+
using Android.Widget;
12+
using Newtonsoft.Json.Linq;
13+
14+
namespace BeatOn.ClientModels
15+
{
16+
public class ClientUpdateSyncFeedConfig : MessageBase
17+
{
18+
public override MessageType Type => MessageType.UpdateSyncFeedConfig;
19+
20+
public Guid ID { get; set; }
21+
22+
//will this work?
23+
public JObject FeedConfig { get; set; }
24+
25+
}
26+
}

BeatOn/ClientModels/MessageType.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public enum MessageType
3434
MoveSongInPlaylist,
3535
MovePlaylist,
3636
DeleteMod,
37-
ChangeColor
37+
ChangeColor,
38+
SyncSaber,
39+
UpdateSyncFeedConfig
3840
}
3941
}

BeatOn/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace BeatOn
1515
public static class Constants
1616
{
1717

18+
public const string SYNC_SABER_CONFIG = "syncsaberservice.json";
1819
public const string LAST_COMMITTED_CONFIG = "config.json";
1920
public const string LAST_TEMP_CONFIG = "tempconfig.json";
2021
public const string LOGGLY_TOKEN = "271fee44-1ebb-4629-861e-e15d8e5a4659";

BeatOn/Core/BeatOnCore.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class BeatOnCore : IDisposable
2727
{
2828
private Context _context;
2929
public ImportManager ImportManager { get; private set; }
30+
public SyncManager SyncManager { get; private set; }
3031

3132
public BeatOnCore(Context context, Action<string> triggerPackageInstall, Action<string> triggerPackageUninstall, Action<string> triggerStopPackage)
3233
{
@@ -38,6 +39,7 @@ public BeatOnCore(Context context, Action<string> triggerPackageInstall, Action<
3839
_SongDownloadManager.StatusChanged += _SongDownloadManager_StatusChanged;
3940
_triggerStopPackage = triggerStopPackage;
4041
ImageUtils.Instance = new ImageUtilsDroid();
42+
SyncManager = new SyncManager(_qaeConfig, _SongDownloadManager, () => CurrentConfig, () => Engine, ShowToast);
4143
KillBeatSaber();
4244
}
4345

@@ -138,6 +140,10 @@ private void DisposeEngine()
138140
/// </summary>
139141
private bool SaveCommittedConfigToDisk()
140142
{
143+
//todo: this is SO the wrong place for this. Suppose I'll move it after I put it here for testing. probably should save instantly on update and not be part of sync
144+
SyncManager.Save();
145+
146+
141147
if (!CurrentConfig.IsCommitted || Engine.HasChanges)
142148
return false;
143149
lock (_configFileLock)
@@ -406,7 +412,8 @@ private void _SongDownloadManager_StatusChanged(object sender, DownloadStatusCha
406412
//ShowToast("Downloading file...", dl.DownloadUrl.ToString(), ToastType.Info, 3);
407413
break;
408414
case DownloadStatus.Failed:
409-
ShowToast("Download failed", dl.DownloadUrl.ToString(), ToastType.Error, 5);
415+
if (!dl.SuppressToast)
416+
ShowToast("Download failed", dl.DownloadUrl.ToString(), ToastType.Error, 5);
410417
break;
411418
case DownloadStatus.Processed:
412419
//ShowToast("Download Processed", dl.DownloadUrl.ToString(), ToastType.Success, 3);
@@ -493,7 +500,11 @@ private void SetupWebApp()
493500
_webServer.Router.AddRoute("POST", "/mod/exit", new PostExit(HardQuit));
494501
_webServer.Router.AddRoute("POST", "/mod/package", new PostPackageAction(SendPackageLaunch, SendPackageStop));
495502
_webServer.Router.AddRoute("PUT", "/beatsaber/config", new PutConfig(() => Engine, () => CurrentConfig, SendConfigChangeMessage));
496-
_webServer.Router.AddRoute("POST", "beatsaber/config/restore", new PostConfigRestore(() => Engine, () => _qaeConfig, ()=> CurrentConfig, SendConfigChangeMessage));
503+
_webServer.Router.AddRoute("POST", "/beatsaber/config/restore", new PostConfigRestore(() => Engine, () => _qaeConfig, ()=> CurrentConfig, SendConfigChangeMessage));
504+
505+
//TEST ONE
506+
_webServer.Router.AddRoute("GET", "/beatsaber/sync", new GetSyncConfig(() => SyncManager));
507+
_webServer.Router.AddRoute("POST", "/beatsaber/sync", new PostSyncSync(() => SyncManager));
497508

498509

499510
//if you add a new MessageType and a handler here, make sure the type is added in MessageTypeConverter.cs

0 commit comments

Comments
 (0)