Profile contain various data which launcher need.
All Game Versions has its own profile, even old alpha version and forge.
You can find it at (GameDirectory)₩versions₩(any-version)₩(version-name).json.
MProfileInfo is metadata of profile, containing Name, Profile Path(Url), Type(Release, Snapshot, Old), ReleaseTime.
and this code get profile info :
It will return all metadata from mojang web server and your game directory.
but you can choose source :
// get profiles from mojang server
var web = MProfileInfo.GetProfilesFromWeb();
// get profiles from game directory
var local = MProfileInfo.GetProfilesFromLocal();
5. Choose ProfileInfo and Parse
In order to use profile data, you should parse profile.
This simple code will search version from metadatas, and return parsed profile data.
and the handler methods of ChangeFile and ChangeProgress event is :
private void Downloader_ChangeProgress(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
// when download file was changed
// 20%, 30%, 80%, ...
Console.WriteLine("{0}%", e.ProgressPercentage);
}
private void Downloader_ChangeFile(DownloadFileChangedEventArgs e)
{
// when the progress of current downloading file was changed
// [Library] hi.jar - 3/51
Console.WriteLine("[{0}] {1} - {2}/{3}", e.FileKind.ToString(), e.FileName, e.ProgressedFileCount, e.TotalFileCount);
}
DownloadAll() method check the existence of game file, and download game file from mojang server if file is not exist or not valid(compare hash).
7. Make game args and Launch
var option = new MLaunchOption()
{
// must require
StartProfile = profile,
JavaPath = "java.exe", //SET YOUR JAVA PATH (if you want autoset, goto wiki)
MaximumRamMb = 1024, // MB
Session = session,
// not require
ServerIP = "", // connect server directly
LauncherName = "", // display launcher name at main window
CustomJavaParameter = "" // set your own java args
};
var launch = new MLaunch(option);
var process = launch.GetProcess();
process.Start();
请发表评论