package Ġcom . github . woo j ia hao . utility Ċ Ċ import Ġcom . github . woo j ia hao . extensions . read Ċ import Ġcom . github . woo j ia hao . models . Configuration Ċ import Ġcom . github . woo j ia hao . models . Configuration Component Ċ import Ġcom . github . woo j ia hao . models . Status Ċ import Ġcom . google . gson . Gson Ċ import Ġcom . google . gson . JsonObject Ċ import Ġjava . io . File Ċ Ċ const Ġval ĠBACK UP _ FILE _ NAME Ġ= Ġ". backup . json " Ċ Ċ fun Ġhas Backup File ( root : ĠString Ġ= Ġ"~ ") Ġ= ĠFile ( path ( root , ĠBACK UP _ FILE _ NAME )). exists () Ċ Ċ fun Ġcreate Backup File ( root : ĠString Ġ= Ġ"~ ") Ġ= ĠFile ( path ( root , ĠBACK UP _ FILE _ NAME )). createNew File () Ċ Ċ fun Ġwrite Configuration ( configuration : ĠConfiguration , Ġroot : ĠString Ġ= Ġ"~ ") Ġ= ĊĠ Ġwith ( File ( path ( root , ĠBACK UP _ FILE _ NAME ))) Ġ{ ĊĠĠĠ Ġwrite Text ( configuration . toJson (). toString ()) ĊĠ Ġ} Ċ Ċ fun Ġload Default Backup Component ( root : ĠString Ġ= Ġ"~ ") Ġ= ĊĠ Ġwrite Configuration ( Configuration ( Configuration Component . DEFAULT ), Ġroot ) Ċ Ċ fun Ġload Configuration ( root : ĠString Ġ= Ġ"~ "): ĠStatus < Configuration > Ġ{ ĊĠ Ġif Ġ(! has Backup File ( root )) Ġ{ ĊĠĠĠ Ġcreate Backup File ( root ) ĊĠĠĠ Ġload Default Backup Component ( root ) ĊĠ Ġ} ĊĊĠ Ġval Ġbackup Json Ġ= ĠGson (). read < JsonObject >( File ( path ( root , ĠBACK UP _ FILE _ NAME )). read Text ()) ĊĠ Ġreturn Ġwhen ( val Ġconfiguration Ġ= ĠConfiguration Component . fromJson ( backup Json )) Ġ{ ĊĠĠĠ Ġis ĠStatus . Success Ġ-> ĠStatus . Success ( Configuration ( configuration . value )) ĊĠĠĠ Ġis ĠStatus . Fail Ġ-> ĠStatus . Fail ( Configuration ( configuration . value ), Ġ* configuration . error Components ) ĊĠ Ġ} Ċ } Ċ