public ParseTreeNode(IJPath jpath) : this() { HasInnerClasses = jpath.HasInnerClasses; Path = jpath.Path; ClassPath = jpath.ClassPath; InnerClassPaths = (jpath.InnerClassPaths == null) ? new List <string>() : new List <string>(InnerClassPaths); }
public IClassParser SetBasePath(IJPath basePath) { _basePath = basePath; return(this); }
protected override IDocumentViewModel _InnerOpenDocument(IJPath path) { DecompileDocumentViewModel viewModel; viewModel = Container.Resolve <DecompileDocumentViewModel>(); viewModel.Parent = this; viewModel.Title = Path.GetFileName(path.Path); Documents.Add(viewModel); /*viewModel.TokenSource = new CancellationTokenSource(); * viewModel.DecompileTask = new Task(() => * { * if (MapSourceToMd5.ContainsKey(path.Path)) * { * if (APIHelper.GetMd5Of(path.Path) == MapSourceToMd5[path.Path]) * { * //TODO * } * } * var basedir = Path.GetDirectoryName(path.Path); * var tempPath = Path.GetTempFileName(); * File.Delete(tempPath); * Directory.CreateDirectory(tempPath); * File.Copy(path.Path, Path.Combine(tempPath, Path.GetFileName(path.Path))); * foreach(var p in path.InnerClassPaths) * { * File.Copy(p, Path.Combine(tempPath, Path.GetFileName(p))); * } * var result = Decompiler.Decompile(tempPath, r => MessageWhole = r, viewModel.TokenSource.Token, BaseDirectory + "\\raw.jar"); * * if (result.ResultCode == CommonDecompiler.DecompileResultEnum.DecompileSuccess) * { * viewModel.Load(result.Output); * } * }); * viewModel.DecompileTask.Start();*/ viewModel.DecompTaskTokenSource = new CancellationTokenSource(); IBackgroundTask backgroundTask = null; backgroundTask = Container.Resolve <IBackgroundTaskBuilder>() .WithTask(async obj => { var token = obj as CancellationToken?; if (MapSourceToMd5.ContainsKey(path.Path)) { if (APIHelper.GetMd5Of(path.Path) == MapSourceToMd5[path.Path]) { //TODO } } var basedir = Path.GetDirectoryName(path.Path); var tempPath = Path.GetTempFileName(); File.Delete(tempPath); Directory.CreateDirectory(tempPath); File.Copy(path.Path, Path.Combine(tempPath, Path.GetFileName(path.Path))); if (path.InnerClassPaths != null) { foreach (var p in path.InnerClassPaths) { File.Copy(p, Path.Combine(tempPath, Path.GetFileName(p))); } } IDecompileResult result = null; try { result = Decompiler.Decompile(tempPath, r => { if (backgroundTask != null) { backgroundTask.TaskDescription = r; } }, token, BaseDirectory + "\\raw.jar"); if (result.ResultCode == DecompileResultEnum.Success) { var files = Directory.GetFiles(result.OutputDir); #if DEBUG Debug.Assert(files.Length == 1); #endif string newFileName = files[0]; if (EnableDecompiledFileCache) { newFileName = Path.Combine(basedir + '\\', Path.GetFileNameWithoutExtension(files[0]) + ".java"); File.Copy(files[0], newFileName, true); MapSourceToMd5.Add(newFileName, APIHelper.GetMd5Of(newFileName)); } StatusMessage = backgroundTask.TaskDescription = "Processing " + path.ClassPath; await viewModel.LoadAsync(newFileName, path); Application.Current.Dispatcher.Invoke(() => { if (!(Manager.ActiveContent is IDocumentViewModel)) { ActivateDocument(viewModel); } }); } else { Container.Resolve <IDialogService>().ReportError(result.ResultCode.ToString(), _ => { }); Application.Current.Dispatcher.Invoke(() => { Documents.Remove(viewModel); }); } } catch (Exception e) { if (e is OperationCanceledException) { Application.Current.Dispatcher.Invoke(() => { Documents.Remove(viewModel); }); } else { string message = null; if (e is Win32Exception win32Exception) { message = $"Unexpected exception:\n{win32Exception.Message}\nHRESULT is {System.Runtime.InteropServices.Marshal.GetHRForLastWin32Error().ToString("x")}"; } else { message = $"Unexpected exception:\n{e.Message}\n"; } Container.Resolve <IDialogService>().ReportError(message, r => { }, e.StackTrace); Application.Current.Dispatcher.Invoke(() => { Documents.Remove(viewModel); }); } } if (token.HasValue) { token.Value.ThrowIfCancellationRequested(); } Directory.Delete(tempPath, true); StatusMessage = "Ready"; }, viewModel.DecompTaskTokenSource.Token) .WithName($"{Decompiler.GetDecompilerInfo().FriendlyName}:{Path.GetFileName(path.Path)}") .WithDescription($"Decompiler started") .Build(); viewModel.AttachDecompileTask(backgroundTask); viewModel.BackgroundTask.Start(); return(viewModel); }