Skip to content

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
wants to merge 1 commit into
base: assetstoolsv2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions AssetsView/Winforms/StartScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

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.

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);
Copy link
Owner

Choose a reason for hiding this comment

The 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, 5.0.0f1 first 6 characters are 5.0.0f not 5.0) Just use split for everything so we're sure it's correct.

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;
Expand Down