@@ -54,6 +54,7 @@ import {
54
54
} from './utils/rtsFlagsSettings' ;
55
55
import { toggleRTSFlagsModeChannel } from './ipc/toggleRTSFlagsModeChannel' ;
56
56
import { containsRTSFlags } from './utils/containsRTSFlags' ;
57
+ import * as fs from 'fs' ;
57
58
58
59
/* eslint-disable consistent-return */
59
60
// Global references to windows to prevent them from being garbage collected
@@ -133,8 +134,54 @@ const handleWindowClose = async (event: Event | null | undefined) => {
133
134
await safeExit ( ) ;
134
135
} ;
135
136
137
+ const clearLedger = async ( ) => {
138
+ const flagFileShortName = 'has_upgraded_to_pv_10' ;
139
+ const chainLedgerDir = 'chain/ledger' ;
140
+
141
+ const flagFileLongName = path . join (
142
+ launcherConfig . stateDir ,
143
+ flagFileShortName
144
+ ) ;
145
+
146
+ // Check if the flag file exists
147
+ if ( fs . existsSync ( flagFileLongName ) ) {
148
+ console . log ( `${ flagFileLongName } found. NoHskpg.` ) ;
149
+ } else {
150
+ try {
151
+ const chainLedgerLongName = path . join (
152
+ launcherConfig . stateDir ,
153
+ chainLedgerDir
154
+ ) ;
155
+
156
+ const files = fs . readdirSync ( chainLedgerLongName ) ;
157
+
158
+ for ( const file of files ) {
159
+ // DelIterator
160
+ const filePath = path . join ( chainLedgerLongName , file ) ;
161
+ if ( fs . lstatSync ( filePath ) . isFile ( ) ) {
162
+ // ?it's a file
163
+ fs . unlinkSync ( filePath ) ;
164
+ console . log ( `HskpgDone: ${ filePath } ` ) ;
165
+ }
166
+ }
167
+
168
+ // Create v10-upgraded completed marker
169
+ fs . writeFileSync ( flagFileLongName , 'HskpgNwFlag' ) ;
170
+ } catch ( err ) {
171
+ console . error ( `Error removing files: ${ err } ` ) ;
172
+ }
173
+ }
174
+ } ;
175
+
176
+
177
+
178
+
136
179
const onAppReady = async ( ) => {
137
180
setupLogging ( ) ;
181
+
182
+ await clearLedger ( ) ;
183
+
184
+
138
185
await logUsedVersion (
139
186
environment . version ,
140
187
path . join ( pubLogsFolderPath , 'Daedalus-versions.json' )
0 commit comments