-
Notifications
You must be signed in to change notification settings - Fork 111
Fix for selecting correct classdatabasefile for closest Unity version… #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wh0am15533
wants to merge
1
commit into
nesrak1:assetstoolsv2
Choose a base branch
from
wh0am15533:master
base: assetstoolsv2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,11 +155,41 @@ public void LoadMainAssetsFile(AssetsFileInstance inst) | |
helper.LoadClassDatabaseFromPackage(inst.file.typeTree.unityVersion); | ||
if (helper.classFile == null) | ||
{ | ||
//may still not work but better than nothing I guess | ||
//in the future we should probably do a selector | ||
//like uabe does | ||
// Modification to find closest Unity version match | ||
int index = helper.classPackage.header.files.FindIndex(f => f.name.StartsWith("U" + inst.file.typeTree.unityVersion)); | ||
if (index >= 0) // -1 mean's it isn't in current tpk | ||
{ | ||
helper.classFile = helper.classPackage.files[index]; // If am.classFile is Null you get errors. | ||
} | ||
else | ||
{ | ||
List<ClassDatabaseFile> files = helper.classPackage.files; | ||
|
||
// Filter all classDbFiles for matching versions | ||
var unityMajMinVer = inst.file.typeTree.unityVersion.Substring(0, 6); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be careful about using substring like this since the length of major+minor versions aren't always 6 (for example, |
||
var filter1 = files.Where(f => f.header.unityVersions[0].StartsWith(unityMajMinVer)).OrderBy(v => v.header.unityVersions[v.header.unityVersionCount - 1]); | ||
var filter2 = filter1.Where(f => f.header.unityVersions[f.header.unityVersionCount - 1].Trim().Length == inst.file.typeTree.unityVersion.Length).OrderBy(v => v.header.unityVersions[v.header.unityVersionCount - 1]); | ||
|
||
// Get the SubMinor version number | ||
string unitySubMinVer = inst.file.typeTree.unityVersion.Split('.')[2]; | ||
string tmpNum = ""; | ||
if (unitySubMinVer.Length >= 4) { tmpNum = unitySubMinVer.Substring(0, 2); } else { tmpNum = unitySubMinVer.Substring(0, 1); } | ||
|
||
// Make Existing Num List | ||
List<int> nums = new List<int>(); | ||
foreach (var pos in filter2) { nums.Add(int.Parse(pos.header.unityVersions[pos.header.unityVersionCount - 1].Split('.')[2].Substring(0, tmpNum.Length))); } | ||
int closest = nums.Aggregate((x, y) => Math.Abs(x - int.Parse(tmpNum)) < Math.Abs(y - int.Parse(tmpNum)) ? x : y); | ||
|
||
ClassDatabaseFile result = filter2.Where(f => f.header.unityVersions[f.header.unityVersionCount - 1].StartsWith(unityMajMinVer + "." + closest)).Single(); | ||
helper.classFile = result; | ||
} | ||
|
||
|
||
/* ORIGINAL CODE - will be Unity 5.x, due to order of list | ||
//may still not work but better than nothing I guess in the future we should probably do a selector like uabe does | ||
List<ClassDatabaseFile> files = helper.classPackage.files; | ||
helper.classFile = files[files.Count - 1]; | ||
*/ | ||
} | ||
UpdateFileList(); | ||
currentFile = inst; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to put this inside of LoadClassDatabaseFromPackage, that way it works everywhere rather than just here in AssetsView. It needs to be in a different method than LoadAssetsFile anyway.