public StatusProgress()
        {
            InitializeComponent();

            _visualProgress = new VisualProgress(this);

            StatusIndeterminateLabelVisible.PropertyChanged += (sender, args) =>
            {
                if (StatusIndeterminateLabelVisible.Value)
                {
                    StartTimer();
                }
                else
                {
                    StopTimer();
                }
            };
        }
Esempio n. 2
0
        public InstallApkWindow(
            [NotNull] IInstallApkViewModel viewModel
            )
        {
            _viewModel = viewModel;

            InitializeComponent();
            DataContext = viewModel;

            ITaskBarManager taskBarManager = new TaskBarManager(TaskbarItemInfo = new TaskbarItemInfo());
            IVisualProgress visualProgress = StatusProgress.GetVisualProgress();

            viewModel.TaskBarManager.Value = taskBarManager;
            viewModel.VisualProgress.Value = visualProgress;

            visualProgress.SetLabelText(MainResources.AllDone);

            // property changes notification
            viewModel.LogText.PropertyChanged += (sender, args) => LogBox.Dispatcher.Invoke(() => LogBox.ScrollToEnd());
        }
        public MainWindow(
            [NotNull] IAppSettings appSettings,
            [NotNull] ApplicationUtils applicationUtils,
            [NotNull] IMainWindowViewModel viewModel,
            [NotNull] Provider <MainWindow> mainWindowProvider,
            [NotNull] Provider <InstallApkWindow> installApkWindowProvider,
            [NotNull] Provider <AboutWindow> aboutWindowProvider,
            [NotNull] Provider <AdbInstallWindow> adbInstallWindowProvider,
            [NotNull] NotificationManager notificationManager,
            [NotNull] TempUtils tempUtils,
            [NotNull] GlobalVariables globalVariables,
            [NotNull] Utils utils,
            [NotNull] Provider <IApktool> apktoolProvider
            )
        {
            _settings                 = appSettings;
            _applicationUtils         = applicationUtils;
            _mainWindowProvider       = mainWindowProvider;
            _installApkWindowProvider = installApkWindowProvider;
            _aboutWindowProvider      = aboutWindowProvider;
            _adbInstallWindowProvider = adbInstallWindowProvider;
            _notificationManager      = notificationManager;
            _tempUtils                = tempUtils;
            _globalVariables          = globalVariables;
            _utils           = utils;
            _apktoolProvider = apktoolProvider;

            ViewModel   = viewModel;
            DataContext = ViewModel;

            InitializeComponent();

            _taskBarManager = new TaskBarManager(TaskbarItemInfo = new TaskbarItemInfo());

            _visualProgress = StatusProgress.GetVisualProgress();

            _visualProgress.SetLabelText(MainResources.AllDone);
        }
Esempio n. 4
0
        public async Task DownloadJava([NotNull] IVisualProgress visualProgress)
        {
            visualProgress.SetLabelText(MainResources.JavaDownloading);
            visualProgress.ShowIndeterminateLabel();

            bool fileDownloaded;

            const string jreUrl       = @"https://pixelcurves.ams3.digitaloceanspaces.com/SaveToGame/jre_1.7.zip";
            string       fileLocation = Path.Combine(_globalVariables.AppDataPath, "jre.zip");

            LDirectory.CreateDirectory(_globalVariables.AppDataPath);

            using (var client = new WebClient())
            {
                client.DownloadProgressChanged += (sender, args) => visualProgress.SetBarValue(args.ProgressPercentage);

                while (true)
                {
                    try
                    {
                        await client.DownloadFileTaskAsync(jreUrl, fileLocation);

                        fileDownloaded = true;
                        break;
                    }
                    catch (Exception ex)
                    {
                        var promt = MessBox.ShowDial(
                            string.Format(MainResources.JavaDownloadFailed, ex.Message),
                            MainResources.Error,
                            MainResources.No,
                            MainResources.Yes
                            );

                        if (promt == MainResources.Yes)
                        {
                            continue;
                        }

                        fileDownloaded = false;
                        break;
                    }
                }
            }

            if (fileDownloaded)
            {
                visualProgress.SetLabelText(MainResources.JavaExtracting);
                visualProgress.SetBarIndeterminate();

                using (var zipFile = new ZipFile(fileLocation))
                {
                    await Task.Factory.StartNew(() => zipFile.ExtractAll(_globalVariables.PathToPortableJre));
                }

                LFile.Delete(fileLocation);
            }

            visualProgress.HideIndeterminateLabel();
            visualProgress.SetLabelText(MainResources.AllDone);
        }
Esempio n. 5
0
        private void ProcessAll(byte[] xxhdpiBytes, byte[] xhdpiBytes, byte[] hdpiBytes, byte[] mdpiBytes, Dispatcher uiThreadDispatcher)
        {
            const string internalDataInApkName = "data.save";
            const string externalDataInApkName = "extdata.save";

            IVisualProgress visualProgress = VisualProgress.Value;
            ITaskBarManager taskBarManager = TaskBarManager.Value;

            string apkFile         = Apk.Value;
            string saveFile        = Save.Value;
            string androidDataFile = Data.Value;

            string[]   androidObbFiles    = (string[])Obb.Value?.Clone() ?? new string[0];
            string     appTitle           = AppTitle.Value;
            bool       alternativeSigning = _settings.AlternativeSigning;
            BackupType backupType         = _settings.BackupType;

            // initializing
            visualProgress?.SetBarIndeterminate();
            visualProgress?.ShowBar();
            visualProgress?.ShowIndeterminateLabel();
            taskBarManager?.SetProgress(0);
            taskBarManager?.SetUsualState();

            void SetStep(string step, int stepNumber)
            {
                WindowTitle.Value = step;
                Log(step);

                const int maxStep    = 5;
                int       percentage = (stepNumber - 1) * 100 / maxStep;

                visualProgress?.SetLabelText(step);
                taskBarManager?.SetProgress(percentage);
            }

            SetStep(MainResources.StepInitializing, 1);

            string resultFilePath = Path.Combine(
                Path.GetDirectoryName(apkFile) ?? string.Empty,
                Path.GetFileNameWithoutExtension(apkFile) + "_mod.apk"
                );

            IApktool            apktool     = _apktoolProvider.Get();
            IProcessDataHandler dataHandler = new ProcessDataCombinedHandler(Log);

            ITempFileProvider   tempFileProvider   = _tempUtils.CreateTempFileProvider();
            ITempFolderProvider tempFolderProvider = _tempUtils.CreateTempFolderProvider();

            using (var stgContainerExtracted = AndroidHelper.Logic.Utils.TempUtils.UseTempFolder(tempFolderProvider))
            {
                // extracting SaveToGame container app
                SetStep(MainResources.CopyingStgApk, 2);

                string containerZipPath = Path.Combine(_globalVariables.PathToResources, "apk.zip");
                using (var zip = new ZipFile(containerZipPath)
                {
                    Password = _globalVariables.AdditionalFilePassword
                })
                {
                    zip.ExtractAll(stgContainerExtracted.TempFolder);
                }

                SetStep(MainResources.AddingData, 3);

                // creating assets folder for data
                string stgContainerAssetsPath = Path.Combine(stgContainerExtracted.TempFolder, "assets");
                LDirectory.CreateDirectory(stgContainerAssetsPath);

                // adding backup
                if (!string.IsNullOrEmpty(saveFile))
                {
                    string internalDataPath = Path.Combine(stgContainerAssetsPath, internalDataInApkName);
                    string externalDataPath = Path.Combine(stgContainerAssetsPath, externalDataInApkName);

                    ApkModifer.ParseBackup(
                        pathToBackup: saveFile,
                        backupType: backupType,
                        resultInternalDataPath: internalDataPath,
                        resultExternalDataPath: externalDataPath,
                        tempFolderProvider: tempFolderProvider
                        );
                }

                // adding external data
                if (!string.IsNullOrEmpty(androidDataFile))
                {
                    LFile.Copy(
                        androidDataFile,
                        Path.Combine(stgContainerAssetsPath, externalDataInApkName)
                        );
                }

                // adding obb files
                if (androidObbFiles.Length != 0)
                {
                    using (var obbParts = AndroidHelper.Logic.Utils.TempUtils.UseTempFolder(tempFolderProvider))
                    {
                        ApkModifer.SplitObbFiles(
                            obbFilePaths: androidObbFiles,
                            partsFolderPath: obbParts.TempFolder,
                            // todo: add progress
                            progressNotifier: null
                            );

                        string assetsDir = Path.Combine(stgContainerExtracted.TempFolder, "assets", "111111222222333333");
                        LDirectory.CreateDirectory(assetsDir);

                        IEnumerable <string> filesToAdd = LDirectory.EnumerateFiles(obbParts.TempFolder);
                        foreach (var file in filesToAdd)
                        {
                            LFile.Copy(file, Path.Combine(assetsDir, Path.GetFileName(file)));
                        }
                    }
                }

                // adding resigned apk to container
                using (var sourceResigned = AndroidHelper.Logic.Utils.TempUtils.UseTempFile(tempFileProvider))
                {
                    apktool.Sign(
                        sourceApkPath: apkFile,
                        signedApkPath: sourceResigned.TempFile,
                        tempFileProvider: tempFileProvider,
                        dataHandler: dataHandler,
                        deleteMetaInf: !alternativeSigning
                        );

                    LFile.Copy(
                        sourceFileName: sourceResigned.TempFile,
                        destFileName: Path.Combine(stgContainerAssetsPath, "install.bin"),
                        overwrite: false
                        );
                }

                // modifying AndroidManifest
                {
                    string pathToManifest = Path.Combine(stgContainerExtracted.TempFolder, "AndroidManifest.xml");

                    string sourcePackageName;
                    using (var sourceManifest = AndroidHelper.Logic.Utils.TempUtils.UseTempFile(tempFileProvider))
                    {
                        apktool.ExtractSimpleManifest(
                            apkPath: apkFile,
                            resultManifestPath: sourceManifest.TempFile,
                            tempFolderProvider: tempFolderProvider
                            );

                        sourcePackageName = new AndroidManifest(sourceManifest.TempFile).Package;
                    }

                    LFile.WriteAllText(
                        pathToManifest,
                        LFile.ReadAllText(pathToManifest, Encoding.UTF8)
                        .Replace("change_package", sourcePackageName)
                        .Replace("@string/app_name", appTitle)
                        );
                }

                // adding icons
                {
                    string iconsFolder = Path.Combine(stgContainerExtracted.TempFolder, "res", "mipmap-");

                    void DeleteIcon(string folder) =>
                    LFile.Delete(Path.Combine($"{iconsFolder}{folder}", "ic_launcher.png"));

                    DeleteIcon("xxhdpi-v4");
                    DeleteIcon("xhdpi-v4");
                    DeleteIcon("hdpi-v4");
                    DeleteIcon("mdpi-v4");

                    void WriteIcon(string folder, byte[] imageBytes) =>
                    LFile.WriteAllBytes(Path.Combine($"{iconsFolder}{folder}", "ic_launcher.png"), imageBytes);

                    WriteIcon("xxhdpi-v4", xxhdpiBytes);
                    WriteIcon("xhdpi-v4", xhdpiBytes);
                    WriteIcon("hdpi-v4", hdpiBytes);
                    WriteIcon("mdpi-v4", mdpiBytes);
                }

                // compiling + signing
                using (var compiledContainer = AndroidHelper.Logic.Utils.TempUtils.UseTempFile(tempFileProvider))
                {
                    // compiling
                    SetStep(MainResources.StepCompiling, 4);

                    // todo: check errors
                    List <Error> compilationErrors;
                    apktool.Compile(
                        projectFolderPath: stgContainerExtracted.TempFolder,
                        destinationApkPath: compiledContainer.TempFile,
                        dataHandler: dataHandler,
                        errors: out compilationErrors
                        );

                    if (compilationErrors.Count > 0)
                    {
                        Log(MainResources.ErrorUp);
                        return;
                    }

                    // signing
                    SetStep(MainResources.StepSigning, 5);

                    apktool.Sign(
                        sourceApkPath: compiledContainer.TempFile,
                        signedApkPath: resultFilePath,
                        tempFileProvider: tempFileProvider,
                        dataHandler: dataHandler,
                        deleteMetaInf: !alternativeSigning
                        );
                }
            }

            visualProgress?.HideIndeterminateLabel();
            visualProgress?.HideBar();
            SetStep(MainResources.AllDone, 6);
            Log(string.Empty);
            Log($"{MainResources.Path_to_file} {resultFilePath}");

            _globalVariables.LatestModdedApkPath = resultFilePath;

            if (_settings.Notifications)
            {
                _notificationManager.Show(
                    title: MainResources.Information_Title,
                    text: MainResources.ModificationCompletedContent
                    );
            }

            string dialogResult = MessBox.ShowDial(
                $"{MainResources.Path_to_file} {resultFilePath}",
                MainResources.Successful,
                MainResources.OK, MainResources.Open, MainResources.Install
                );

            if (dialogResult == MainResources.Open)
            {
                Process.Start("explorer.exe", $"/select,{resultFilePath}");
            }
            else if (dialogResult == MainResources.Install)
            {
                uiThreadDispatcher.Invoke(() => _adbInstallWindowProvider.Get().ShowDialog());
            }

            taskBarManager?.SetNoneState();
        }