Skip to content

Commit

Permalink
Storage: Fix iOS URI path problem (attempt 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
0thElement committed Aug 24, 2023
1 parent 9580c0e commit 4dd728a
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
targetPlatform: iOS
buildName: ArcCreate
versioning: Custom
version: "0.1"
version: "0.2"

- uses: actions/upload-artifact@v2
with:
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/ChartFormat/FileAccess/IFileAccessWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.IO;

namespace ArcCreate.ChartFormat
{
public interface IFileAccessWrapper
{
string GetFileUri(string path);
Uri GetFileUri(string path);

Option<string[]> ReadFileByLines(string path);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/ChartFormat/FileAccess/PhysicalFileAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace ArcCreate.ChartFormat
{
public class PhysicalFileAccess : IFileAccessWrapper
{
public string GetFileUri(string path)
public Uri GetFileUri(string path)
{
return "file:///" + Uri.EscapeUriString(path.Replace("\\", "/"));
return new Uri(path);
}

public Option<string[]> ReadFileByLines(string path)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/ChartFormat/FileAccess/VirtualFileAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public VirtualFileAccess(Stream stream)
streamWriter = new StreamWriter(stream);
}

public string GetFileUri(string path)
public Uri GetFileUri(string path)
{
return "file:///" + Uri.EscapeUriString(path.Replace("\\", "/"));
return new Uri(path);
}

public Option<string[]> ReadFileByLines(string path) => data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void SetupScript(Script script)

public void Rebuild()
{
Services.Gameplay.Scenecontrol.ScenecontrolFolder = "file:///" + Values.ScenecontrolFolder;
Services.Gameplay.Scenecontrol.ScenecontrolFolder = Values.ScenecontrolFolder;
Clean();
RunScript();
ExecuteEvents();
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Compose/Project/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private void LoadChart(ChartSettings chart)

if (parseResult.IsOk)
{
gameplayData.LoadChart(reader, "file:///" + Path.GetDirectoryName(path));
gameplayData.LoadChart(reader, Path.GetDirectoryName(path));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public RawEditorFileAccess(string chartData, string chartPath)
virt = new VirtualFileAccess(chartData);
}

public string GetFileUri(string path)
public Uri GetFileUri(string path)
{
return "file:///" + Uri.EscapeUriString(path.Replace("\\", "/"));
return new Uri(path);
}

public Option<string[]> ReadFileByLines(string path)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Compose/Project/RawEditor/RawEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void ApplyChanges()
int timing = Services.Gameplay.Audio.AudioTiming;
ChartReader reader = ChartReaderFactory.GetReader(new RawEditorFileAccess(rawChartData, absoluteMainChartPath), absoluteMainChartPath);
reader.Parse();
gameplayData.LoadChart(reader, "file:///" + Path.GetDirectoryName(absoluteMainChartPath));
gameplayData.LoadChart(reader, Path.GetDirectoryName(absoluteMainChartPath));
Services.Gameplay.Audio.AudioTiming = timing;
}

Expand Down
7 changes: 0 additions & 7 deletions Assets/Scripts/Gameplay/Camera/CameraService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using ArcCreate.Gameplay.Data;
using ArcCreate.Utility.Extension;
using DG.Tweening;
using UnityEngine;

namespace ArcCreate.Gameplay.GameplayCamera
Expand All @@ -10,7 +9,6 @@ public class CameraService : MonoBehaviour, ICameraService, ICameraControl
{
[SerializeField] private Camera backgroundCamera;
[SerializeField] private Camera overlayCamera;
[SerializeField] private Transform skyInputLabel;
[SerializeField] private RectTransform backgroundRect;
private float currentTilt;
private float currentArcPos;
Expand Down Expand Up @@ -160,11 +158,6 @@ public void UpdateCamera(int currentTiming)
return;
}

skyInputLabel.localPosition = new Vector3(
Mathf.LerpUnclamped(Values.SkyInputLabelX, Values.SkyInputLabelXTablet, AspectAdjustment),
skyInputLabel.localPosition.y,
skyInputLabel.localPosition.z);

Vector3 prevPosition = backgroundCamera.transform.localPosition;
Vector3 position = ResetPosition + translationExternal;
Quaternion lookAtRotation = Quaternion.LookRotation(
Expand Down
14 changes: 7 additions & 7 deletions Assets/Scripts/Gameplay/GameplayData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ public void LoadJacket(string path)
/// Set the chart file for this system.
/// </summary>
/// <param name="reader">The chart reader defining the chart.</param>
/// <param name="sfxParentUri">The parent uri for loading custom SFX files.</param>
/// <param name="sfxParentFolder">The parent folder for loading custom SFX files.</param>
/// <param name="fileAccess">Custom file accessor.</param>
public void LoadChart(ChartReader reader, string sfxParentUri, IFileAccessWrapper fileAccess = null)
public void LoadChart(ChartReader reader, string sfxParentFolder, IFileAccessWrapper fileAccess = null)
{
Services.Chart.LoadChart(reader);
Services.Hitsound.LoadCustomSfxs(sfxParentUri, fileAccess).Forget();
Services.Hitsound.LoadCustomSfxs(sfxParentFolder, fileAccess).Forget();
OnChartFileLoad?.Invoke();
}

Expand All @@ -218,7 +218,7 @@ public void SetDefaultBackground()
isUsingDefaultBackground = true;
}

public async UniTask LoadAudioFromHttp(string uri, string ext)
public async UniTask LoadAudioFromHttp(Uri uri, string ext)
{
if (AudioClip.Value != null)
{
Expand All @@ -243,7 +243,7 @@ public async UniTask LoadAudioFromHttp(string uri, string ext)
}
}

public async UniTask LoadJacketFromHttp(string uri)
public async UniTask LoadJacketFromHttp(Uri uri)
{
if (Jacket.Value != null && !isUsingDefaultJacket)
{
Expand Down Expand Up @@ -274,7 +274,7 @@ public async UniTask LoadJacketFromHttp(string uri)
}
}

public async UniTask LoadBackgroundFromHttp(string uri)
public async UniTask LoadBackgroundFromHttp(Uri uri)
{
if (Background.Value != null && !isUsingDefaultBackground)
{
Expand Down Expand Up @@ -313,7 +313,7 @@ public void LoadVideoBackground(string path, bool isUri)
internal async UniTask StartLoadingAudio(string path)
{
using (UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(
Uri.EscapeUriString("file:///" + path.Replace("\\", "/")),
new Uri(path),
path.EndsWith("wav") ? AudioType.WAV : AudioType.OGGVORBIS))
{
await req.SendWebRequest();
Expand Down
9 changes: 4 additions & 5 deletions Assets/Scripts/Gameplay/Hitsound/HitsoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void PlayArcTapHitsound(int timing, string sfx, bool isFromJudgement)
}
}

public async UniTask LoadCustomSfxs(string parentUri, IFileAccessWrapper fileAccess)
public async UniTask LoadCustomSfxs(string parentFolder, IFileAccessWrapper fileAccess)
{
IsLoaded = false;

Expand Down Expand Up @@ -114,7 +114,7 @@ public async UniTask LoadCustomSfxs(string parentUri, IFileAccessWrapper fileAcc
finalSfx = finalSfx + ".wav";
}

string uri = fileAccess == null ? Path.Combine(parentUri, finalSfx) : fileAccess.GetFileUri(finalSfx);
Uri uri = fileAccess == null ? new Uri(Path.Combine(parentFolder, finalSfx)) : fileAccess.GetFileUri(finalSfx);
if (uri != null)
{
loadTasks.Add(LoadCustomSfx(sfx, uri));
Expand All @@ -137,12 +137,11 @@ public void ResetHitsoundHistory()
playedArcHitsoundTimings.Clear();
}

private async UniTask LoadCustomSfx(string sfx, string uri)
private async UniTask LoadCustomSfx(string sfx, Uri uri)
{
try
{
using (UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(
Uri.EscapeUriString(uri.Replace("\\", "/")), AudioType.WAV))
using (UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.WAV))
{
await req.SendWebRequest();
if (!string.IsNullOrWhiteSpace(req.error))
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Gameplay/Hitsound/IHitsoundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public interface IHitsoundService
/// <summary>
/// Loads all sfx file referenced by the currently loaded chart from sfxParentUri.
/// </summary>
/// <param name="sfxParentUri">Where to load sfx files from.</param>
/// <param name="parentFolder">Parent folder of where to load sfx files from.</param>
/// <param name="fileAccess">Custom file accessor.</param>
/// <returns>Unitask instance.</returns>
UniTask LoadCustomSfxs(string sfxParentUri, IFileAccessWrapper fileAccess);
UniTask LoadCustomSfxs(string parentFolder, IFileAccessWrapper fileAccess);

void UpdateHitsoundHistory(int currentTiming);

Expand Down
8 changes: 4 additions & 4 deletions Assets/Scripts/Gameplay/Scenecontrol/Controllers/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public ImageController CreateImage(
spriteTasks.Add(GetSprite(
new SpriteDefinition
{
Uri = customFileAccess?.GetFileUri(Path.Combine("Scenecontrol", imgPath)) ?? Path.Combine(Services.Scenecontrol.ScenecontrolFolder, imgPath),
Uri = customFileAccess?.GetFileUri(Path.Combine("Scenecontrol", imgPath)) ?? new Uri(Path.Combine(Services.Scenecontrol.ScenecontrolFolder, imgPath)),
Pivot = pivotVec,
},
cts.Token).ContinueWith(sprite => c.Image.sprite = sprite));
Expand Down Expand Up @@ -438,7 +438,7 @@ public SpriteController CreateSprite(
spriteTasks.Add(GetSprite(
new SpriteDefinition
{
Uri = customFileAccess?.GetFileUri(Path.Combine("Scenecontrol", imgPath)) ?? Path.Combine(Services.Scenecontrol.ScenecontrolFolder, imgPath),
Uri = customFileAccess?.GetFileUri(Path.Combine("Scenecontrol", imgPath)) ?? new Uri(Path.Combine(Services.Scenecontrol.ScenecontrolFolder, imgPath)),
Pivot = pivotVec,
},
cts.Token).ContinueWith(sprite => c.SpriteRenderer.sprite = sprite));
Expand Down Expand Up @@ -845,7 +845,7 @@ private async UniTask<Sprite> GetSprite(SpriteDefinition definition, Cancellatio
}

spriteCache.Add(definition, null);
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(Uri.EscapeUriString(definition.Uri.Replace("\\", "/"))))
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(definition.Uri))
{
try
{
Expand Down Expand Up @@ -914,7 +914,7 @@ private void Awake()

private struct SpriteDefinition
{
public string Uri;
public Uri Uri;
public Vector2 Pivot;
}
}
Expand Down
19 changes: 12 additions & 7 deletions Assets/Scripts/Remote/GameplayControl/RemoteGameplayControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private async UniTask RetrieveAllFiles(byte[] data)

private async UniTask RetrieveChart()
{
string uri = GetURI("chart");
Uri uri = GetURI("chart");
using (UnityWebRequest req = UnityWebRequest.Get(uri))
{
await req.SendWebRequest();
Expand All @@ -191,7 +191,7 @@ private async UniTask RetrieveChart()
string chartData = req.downloadHandler.text;
var reader = new AffChartReader(new VirtualFileAccess(chartData), string.Empty, string.Empty, string.Empty);
reader.Parse();
gameplayData.LoadChart(reader, GetURI("sfx/"));
gameplayData.LoadChart(reader, GetURIString("sfx/"));
}
}

Expand Down Expand Up @@ -228,7 +228,7 @@ private async UniTask RetrieveBackground(bool useDefault)

private async UniTask RetrieveMetadata(string chartPath)
{
string uri = GetURI("metadata");
Uri uri = GetURI("metadata");
using (UnityWebRequest req = UnityWebRequest.Get(uri))
{
await req.SendWebRequest();
Expand Down Expand Up @@ -309,7 +309,7 @@ private async UniTask RetrieveMetadata(string chartPath)
gameplayData.DifficultyColor.Value = c;

bool enableVideoBackground = !string.IsNullOrEmpty(chartSettings.VideoPath);
gameplayData.LoadVideoBackground(enableVideoBackground ? GetURI("video") : null, true);
gameplayData.LoadVideoBackground(enableVideoBackground ? GetURIString("video") : null, true);

break;
}
Expand All @@ -319,7 +319,7 @@ private async UniTask RetrieveMetadata(string chartPath)

private async UniTask RetrieveScenecontrol()
{
string uri = GetURI("scjson");
Uri uri = GetURI("scjson");
using (UnityWebRequest req = UnityWebRequest.Get(uri))
{
await req.SendWebRequest();
Expand All @@ -334,13 +334,18 @@ private async UniTask RetrieveScenecontrol()
}

string json = req.downloadHandler.text;
gameplay.Scenecontrol.ScenecontrolFolder = GetURI("scenecontrol/");
gameplay.Scenecontrol.ScenecontrolFolder = GetURIString("scenecontrol/");
gameplay.Scenecontrol.Import(json);
gameplay.Scenecontrol.WaitForSceneLoad();
}
}

private string GetURI(string path)
private Uri GetURI(string path)
{
return new Uri(GetURIString(path));
}

private string GetURIString(string path)
{
var uri = $"http://{requestFileFromIP}:{requestFileFromPort}/{path}";
Debug.Log(uri);
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Storage/Loader/GameplayLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private async UniTask LoadAudio(LevelStorage level, ChartSettings chart)
throw new Exception("Audio file does not exist");
}

string uri = "file:///" + UnityWebRequest.EscapeURL(audioPath.Value.Replace("\\", "/"));
Uri uri = new Uri(audioPath.Value);
await gameplayData.LoadAudioFromHttp(uri, Path.GetExtension(audioPath.Value));
}

Expand All @@ -59,7 +59,7 @@ private async UniTask LoadBackground(LevelStorage level, ChartSettings chart)
return;
}

string uri = "file:///" + UnityWebRequest.EscapeURL(bgPath.Value.Replace("\\", "/"));
Uri uri = new Uri(bgPath.Value);
await gameplayData.LoadBackgroundFromHttp(uri);
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Storage/Loader/StorageFileAccessWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public StorageFileAccessWrapper(LevelStorage level)
this.level = level;
}

public string GetFileUri(string path)
public Uri GetFileUri(string path)
{
Option<string> realPath = level.GetRealPath(path);
if (!realPath.HasValue)
{
return null;
}

return "file:///" + Uri.EscapeUriString(realPath.Value.Replace("\\", "/"));
return new Uri(realPath.Value);
}

public Option<string[]> ReadFileByLines(string path)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Storage/StorageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public async UniTask AssignTexture(RawImage image, IStorageUnit storage, string

Incompletable<Texture> loading = new Incompletable<Texture>();
JacketCache.Add(jacketPath, loading);
string uri = "file:///" + UnityWebRequest.EscapeURL(jacketPath.Replace("\\", "/"));
Uri uri = new Uri(jacketPath);
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(uri))
{
await req.SendWebRequest();
Expand Down Expand Up @@ -223,7 +223,7 @@ public async UniTask<AudioClip> GetAudioClipStreaming(IStorageUnit level, string
}

audioPath = realAudioPath.Value;
string uri = "file:///" + UnityWebRequest.EscapeURL(audioPath.Replace("\\", "/"));
Uri uri = new Uri(audioPath);
using (UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(
uri,
audioPath.EndsWith(".ogg") ? AudioType.OGGVORBIS : AudioType.WAV))
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ PlayerSettings:
androidMaxAspectRatio: 2.1
applicationIdentifier: {}
buildNumber:
iPhone: 37
iPhone: 38
AndroidBundleVersionCode: 1
AndroidMinSdkVersion: 19
AndroidTargetSdkVersion: 0
Expand Down

0 comments on commit 4dd728a

Please sign in to comment.