Skip to content

Commit

Permalink
Added check for existing files to improve startup time and show more …
Browse files Browse the repository at this point in the history
…accurate download progress
  • Loading branch information
katboi01 committed Nov 7, 2024
1 parent d97cb90 commit 510a970
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/UmaDatabase/UmaDatabaseEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public string Path
{
get
{
return $"{Config.Instance.MainPath}/dat/{Url.Substring(0, 2)}/{Url}";
return $"{Config.Instance.MainPath}\\dat\\{Url.Substring(0, 2)}\\{Url}"; //"\\" is consistent with Directory.GetFiles()
}
}

Expand Down
22 changes: 16 additions & 6 deletions Assets/Scripts/UmaViewerDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using static UmaViewerUI;
using System.Threading.Tasks;
using System.Threading;
using System.Linq;

public class UmaViewerDownload : MonoBehaviour
{
Expand Down Expand Up @@ -62,17 +63,18 @@ public static void DownloadAssetSync(UmaDatabaseEntry entry, Action<string , UIM
}
}

public static IEnumerator DownloadAssets(List<UmaDatabaseEntry> entrys, Action<int, int, string> callback = null)
public static IEnumerator DownloadAssets(List<UmaDatabaseEntry> entries, Action<int, int, string> callback = null)
{
callback?.Invoke(0, entrys.Count, "DownLoading");
var percent_num = entrys.Count / 100;
for(int i = 0; i < entrys.Count; i++)
entries = RemoveExistingFilesFromList(entries);
callback?.Invoke(0, entries.Count, "DownLoading");
var percent_num = entries.Count / 100;
for(int i = 0; i < entries.Count; i++)
{
var entry = entrys[i];
var entry = entries[i];
yield return downloadWaitUntil;
if(i % percent_num == 0)
{
callback?.Invoke(i, entrys.Count, "DownLoading");
callback?.Invoke(i, entries.Count, "DownLoading");
}
CurrentCoroutinesCount++;
semaphore.WaitAsync();
Expand Down Expand Up @@ -157,4 +159,12 @@ public static string GetAssetRequestUrl(string hash)
{
return $"{ASSET_BASE_URL}/{hash.Substring(0, 2)}/{hash}";
}

private static List<UmaDatabaseEntry> RemoveExistingFilesFromList(List<UmaDatabaseEntry> entries)
{
//dictionary is used for best performance
var localFiles = Directory.GetFiles($"{Config.Instance.MainPath.Replace("/","\\")}\\dat\\", "*", SearchOption.AllDirectories).ToDictionary(file => file, file => true);
entries = entries.Where(entry => !localFiles.ContainsKey(entry.Path)).ToList();
return entries;
}
}
6 changes: 0 additions & 6 deletions Assets/Scripts/UmaViewerMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ private IEnumerator Start()
Builder.ShaderList = new List<Shader>(shaders.LoadAllAssets<Shader>());
}

public void ChangeAA(int val)
{

}


public void OpenUrl(string url)
{
Application.OpenURL(url);
Expand Down
10 changes: 8 additions & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 22
serializedVersion: 23
productGUID: 466286cbc59748b4ca46e7b05d5929c2
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0
Expand Down Expand Up @@ -134,7 +134,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 2.1.15
bundleVersion: 2.1.16
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand All @@ -150,6 +150,7 @@ PlayerSettings:
m_ColorGamuts: 00000000
targetPixelDensity: 395
resolutionScalingMode: 1
resetResolutionOnWindowResize: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1
applicationIdentifier:
Expand Down Expand Up @@ -596,8 +597,11 @@ PlayerSettings:
switchNetworkInterfaceManagerInitializeEnabled: 1
switchPlayerConnectionEnabled: 1
switchUseNewStyleFilepaths: 0
switchUseLegacyFmodPriorities: 1
switchUseMicroSleepForYield: 1
switchEnableRamDiskSupport: 0
switchMicroSleepForYieldTime: 25
switchRamDiskSpaceSize: 12
ps4NPAgeRating: 12
ps4NPTitleSecret:
ps4NPTrophyPackPath:
Expand Down Expand Up @@ -756,6 +760,7 @@ PlayerSettings:
metroFTAName:
metroFTAFileTypes: []
metroProtocolName:
vcxProjDefaultLanguage:
XboxOneProductId:
XboxOneUpdateKey:
XboxOneSandboxId:
Expand Down Expand Up @@ -799,6 +804,7 @@ PlayerSettings:
m_VersionName:
apiCompatibilityLevel: 6
activeInputHandler: 0
windowsGamepadBackendHint: 0
cloudProjectId:
framebufferDepthMemorylessMode: 0
qualitySettingsNames: []
Expand Down

0 comments on commit 510a970

Please sign in to comment.