1- import { window , workspace , ExtensionContext , commands , Uri , languages , ProgressLocation , Progress , CancellationToken , TextDocument } from 'vscode' ;
2- import { getSmaliDocumentClassName } from './util/smali-util' ;
3- import { promises as fs } from 'fs' ;
4- import { JadxDecompiler } from './decompiler/JadxDecompiler' ;
5- import { join } from "path"
6- import JavaCodeProvider from './provider' ;
1+ import { workspace , ExtensionContext , commands } from 'vscode' ;
2+ import JavaCodeProvider from './provider/JavaCodeProvider' ;
3+ import DecompileCommand from './command/decompile' ;
4+ import clearCacheCommand from './command/clear-cache' ;
75
86export function activate ( context : ExtensionContext ) {
97 const provider = new JavaCodeProvider ( )
10- workspace . registerTextDocumentContentProvider ( JavaCodeProvider . scheme , provider ) ;
11- const outputChannel = window . createOutputChannel ( "Smali2Java" )
12- let decompileCommandRegistration = commands . registerCommand ( "smali2java.decompileCurrentSmaliToJava" , async ( uri : Uri ) => {
13- const jadxPath : string | undefined = workspace . getConfiguration ( "smali2java" ) . get ( "jadxPath" )
14- if ( ! jadxPath ) {
15- window . showErrorMessage ( "Please configure the jadx executable path first" )
16- return
17- }
18- if ( ! ( await fs . stat ( jadxPath ) ) . isFile ( ) ) {
19- window . showErrorMessage ( "Invalid jadx executable path" )
20- return
21- }
22- const document = window . activeTextEditor ?. document
23- if ( ! document ) {
24- window . showErrorMessage ( "No editor is active" )
25- return
26- }
27- const className = getSmaliDocumentClassName ( document )
28- if ( ! className ) {
29- window . showErrorMessage ( "Invalid smali file" )
30- return
31- }
32- window . withProgress ( {
33- location : ProgressLocation . Notification ,
34- title : "Decompiling" ,
35- cancellable : true
36- } , async ( progress : Progress < { message ?: string ; increment ?: number } > , token : CancellationToken ) => {
37- const decompiler = new JadxDecompiler ( jadxPath , join ( context . globalStorageUri . fsPath , "decompiled" , "temp" ) , className )
38- try {
39- const resultJavaFilePath = await decompiler . decompile ( uri . fsPath , outputChannel )
40- const resultUri = Uri . parse ( `${ JavaCodeProvider . scheme } :${ resultJavaFilePath } ` )
41- const loadedDocument = workspace . textDocuments . find ( document => ! document . isClosed && document . uri . toString ( ) == resultUri . toString ( ) )
42- if ( loadedDocument ) {
43- provider . onDidChangeEmitter . fire ( resultUri )
44- await window . showTextDocument ( loadedDocument )
45- return
46- }
47- const textDoc = await workspace . openTextDocument ( resultUri ) ;
48- const javaDoc = await languages . setTextDocumentLanguage ( textDoc , "java" )
49- await window . showTextDocument ( javaDoc )
50- } catch ( err ) {
51- window . showErrorMessage ( "Decompile failed" )
52- }
53- } )
54- } ) ;
55- context . subscriptions . push ( decompileCommandRegistration ) ;
8+ context . subscriptions . push (
9+ workspace . registerTextDocumentContentProvider ( JavaCodeProvider . scheme , provider ) ,
10+ commands . registerCommand ( "smali2java.decompileCurrentSmaliToJava" , DecompileCommand ( context , provider ) ) ,
11+ commands . registerCommand ( "smali2java.clearCache" , clearCacheCommand ( context ) )
12+ ) ;
5613}
5714
58-
59- export function deactivate ( ) { }
15+ export function deactivate ( ) { }
0 commit comments