diff --git a/LoadingPage.xaml.cpp b/LoadingPage.xaml.cpp index df8bf3d23a29c00eb29767035d39831cd7e3b9b4..d6eea71a99ba2b0eb9a3229379814e48fc98a97d 100644 --- a/LoadingPage.xaml.cpp +++ b/LoadingPage.xaml.cpp @@ -52,11 +52,42 @@ LoadingPage::LoadingPage() .then([this](bool config_exists) { if (config_exists) { - this->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this] () { - this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(MainPage::typeid)); - })); + Utils::fileExists(ApplicationData::Current->LocalFolder, "creation.token") + .then([this](bool token_exists) + { + if (token_exists) { + /* we have a token, the config has to be considered as corrupted, summon the wizard */ + + Utils::fileExists(ApplicationData::Current->LocalFolder, ".config\\dring.yml") + .then([this](bool token_exists) + { + if (token_exists) { + StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder; + task<StorageFile^>(storageFolder->GetFileAsync(".config\\dring.yml")).then([this](StorageFile^ folder) + { + folder->DeleteAsync(); + }); + } + }); + + this->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() { + this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(Wizard::typeid)); + })); + } + else { + /* there is no token and we have a config.yml, summon the main page */ + this->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() { + this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(MainPage::typeid)); + })); + } + }); } else { + /* no config file, create the token and summon the wizard*/ + StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder; + + storageFolder->CreateFileAsync("creation.token", CreationCollisionOption::ReplaceExisting); + this->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this] () { this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(Wizard::typeid)); })); diff --git a/RingD.cpp b/RingD.cpp index 63e9a454efc6967da8f3f5581ebb0d3f1c2c3f66..2cdf027b8e2f72ddf6e5f784efa868980d7bd87c 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -528,6 +528,21 @@ RingClientUWP::RingD::startDaemon() } } + + /* at this point the config.yml is safe. */ + Utils::fileExists(ApplicationData::Current->LocalFolder, "creation.token") + .then([this](bool token_exists) + { + if (token_exists) { + StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder; + task<StorageFile^>(storageFolder->GetFileAsync("creation.token")).then([this](StorageFile^ file) + { + file->DeleteAsync(); + }); + } + }); + + while (true) { DRing::pollEvents(); dequeueTasks();