@@ -246,8 +246,22 @@ public static void cleanVersion(Profile profile, String id) {
246246 }
247247
248248 public static void resetVersion (Profile profile , String id ) {
249+ HMCLGameRepository repository = profile .getRepository ();
250+
251+ Path jsonPath = repository .getVersionJson (id );
252+
253+ String originalJson ;
254+ try {
255+ originalJson = Files .readString (jsonPath );
256+ } catch (Exception e ) {
257+ LOG .warning ("Unable to reset instance" , e );
258+ Controllers .dialog (i18n ("message.failed" ) + "\n " + StringUtils .getStackTrace (e ), i18n ("message.error" ), MessageDialogPane .MessageType .ERROR );
259+ return ;
260+ }
261+
262+ final String finalJson = originalJson ;
263+
249264 try {
250- HMCLGameRepository repository = profile .getRepository ();
251265 LibraryAnalyzer analyzer = LibraryAnalyzer .analyze (repository .getResolvedPreservingPatchesVersion (id ), null );
252266 GameBuilder builder = profile .getDependency ().gameBuilder ().name (id ).gameVersion (repository .getGameVersion (id ).orElseThrow ());
253267 for (LibraryAnalyzer .LibraryType item : analyzer .getLibraries ()) {
@@ -259,10 +273,22 @@ public static void resetVersion(Profile profile, String id) {
259273 Controllers .taskDialog (builder .buildAsync ()
260274 .thenRunAsync (repository ::refreshVersions )
261275 .whenComplete (Schedulers .javafx (), (ignored , exception ) -> {
276+ if (exception != null ) {
277+ Files .writeString (jsonPath , finalJson );
278+ LOG .warning ("Unable to reset instance" , exception );
279+ Controllers .dialog (i18n ("message.failed" ) + "\n " + StringUtils .getStackTrace (exception ), i18n ("message.error" ), MessageDialogPane .MessageType .ERROR );
280+ return ;
281+ }
262282 profile .setSelectedVersion (id );
263283 Controllers .getVersionPage ().loadVersion (id , profile );
264284 }), i18n ("version.manage.reset" ), TaskCancellationAction .NO_CANCEL );
265285 } catch (Exception e ) {
286+ try {
287+ Files .writeString (jsonPath , finalJson );
288+ } catch (IOException ex ) {
289+ LOG .warning ("Unable to write json" , e );
290+ }
291+
266292 LOG .warning ("Unable to reset instance" , e );
267293 Controllers .dialog (i18n ("message.failed" ) + "\n " + StringUtils .getStackTrace (e ), i18n ("message.error" ), MessageDialogPane .MessageType .ERROR );
268294 }
0 commit comments