locked
How to restore FutureAccessList from terminated state

    Question

  • Our app keeps track of all user opened files using StorageApplicationPermissions::FutureAccessList, which is an array of Strings. We save these strings to a text file when the app receives the suspend event, restore these strings from the text file when our app is activated with previous state as terminated. The issue is these strings are no long valid after the app recovered from the terminated state. Is there a way to restore FutureAccessList from terminated state?
    • Edited by Leonard Monday, February 11, 2013 4:59 PM
    Monday, February 11, 2013 4:59 PM

Answers

  • The File access sample has a bug that it only checks the MRU or FAL lists if a new file has been stored in scenario1, but if you do so or if you bypass the check on rootPage->SampleFile then you will see that the MRU and FAL both persist correctly.

    --Rob

    • Marked as answer by Jesse Jiang Monday, February 18, 2013 6:57 AM
    Friday, February 15, 2013 1:28 AM
    Owner
  • No, each app has its own access caches.

    --Rob

    • Marked as answer by Leonard Wednesday, February 20, 2013 2:29 PM
    Tuesday, February 19, 2013 6:19 PM
    Owner

All replies

  • Hi Leonard,

    The FutureAccessList should automatically persist its cached settings.

    Can you please explain what you are persisting here? Is it array of strings the tokens returned when caching items with StorageItemAccessList::Add? What do you mean by the strings no longer being valid? Does StorageItemAccessList::ContainsItem reject it? If you iterate through StorageItemAccessList::Entries do you see any values?

    Can you try the File access sample and see if it has the same problem you are having and provide exact repro steps if it does?

    --Rob

    Monday, February 11, 2013 9:43 PM
    Owner
  • Hi Rob, sorry for not providing much details.

    We use FutureAccessList to hope users can reload the files they've opened via FileOpenFicker. This works fine before the app is terminated, but fails after it is reactivated from terminated state. Here is the code we use FAL to reopen a file

    String ^curToken = m_allFALTokens->GetAt(layer_index);
    if (curToken == nullptr || prev_layer_index==layer_index )
        break; // don't reload another sublayer as its parent has been reloaded
    
    // Open the file via the token that was stored when adding this file into the FAL list
    create_task(StorageApplicationPermissions::FutureAccessList->GetFileAsync(curToken)).then([this](StorageFile^ pickedfile)
    

    In the code, the create_task statement throws an exception after the app is reactivated from terminated state.

    Here is the code I add a StorageFile item to FAL

    Windows::Foundation::Collections::IVector<Platform::String^> ^m_allFALTokens;
    
    String ^FalToken = StorageApplicationPermissions::FutureAccessList->Add(storageFile, storageFile->Path);
    m_allFALTokens->Append(FalToken);
    

    Here is the code I save FAL to a text file in suspending event handler

    void App::OnSuspending(Object^ sender, SuspendingEventArgs^ args)
    {
    	(void) sender; // Unused parameter.
    	(void) args; // Unused parameter.
    
        StorageFolder^ localFolder;
        localFolder = ApplicationData::Current->LocalFolder;
    
        auto deferral = args->SuspendingOperation->GetDeferral();
        create_task(localFolder->CreateFileAsync(suspend_filename, CreationCollisionOption::ReplaceExisting)).then(
            [this, deferral](StorageFile^ file) 
        {
            SaveAppData(file);
            deferral->Complete();
        });
    
    	m_MainPage->SaveInternalState(ApplicationData::Current->LocalSettings->Values);
    }
    
    void App::SaveAppData(StorageFile ^suspendfile) 
    {
        std::ofstream out_stream;
    	IVector<String^> ^allFALTokens;
    
        out_stream.open(suspendfile->Path->Data());
        if ( !out_stream )
            return;
    
        // some inrelevant code omitted here
    
        allFALTokens = m_MainPage->GetAllFALTokens();
    	for each ( String^ token in allFALTokens ) {
            out_stream << token->Data() << std::endl;
        }
    
        out_stream << std::flush;
        out_stream.close();
    }
    

    Here is the code I read out the FAL from the text file

    void App::OnLaunched(LaunchActivatedEventArgs^ args)
    {
    	m_MainPage = ref new MainPage();
    
    	if (args->PreviousExecutionState == ApplicationExecutionState::Terminated)
    	{
    		StorageFolder^ localFolder;
    		localFolder = ApplicationData::Current->LocalFolder;
    		// Restore app states from suspend_filename
    		create_task(localFolder->GetFileAsync(suspend_filename)).then([this](StorageFile^ file) 
    		{
    			LoadAppData(file);
    		});
    		
    		m_MainPage->LoadInternalState(ApplicationData::Current->LocalSettings->Values);
    	}
    
    	// Place the page in the current window and ensure that it is active.
    	Window::Current->Content = m_MainPage;
    	Window::Current->Activate();
    }
    
    void App::LoadAppData(StorageFile^ suspendfile) 
    {
        std::ifstream in_stream;
    	IVector<String^> ^allFALTokens;
        micapsproj_param new_proj_param;
        char buf[200];
        wchar_t *wbuf;
        int n;
    
        in_stream.open(suspendfile->Path->Data());
        if ( !in_stream || in_stream.eof() )
            return;
    
    	allFALTokens = ref new Vector<String^>();
    	while ( !in_stream.eof() ) {
    		in_stream >> buf;
    		ConvertStringA2W(buf, &wbuf);
    		allFALTokens->Append(ref new String(wbuf));
            free(wbuf);
    	}
    	m_MainPage->SetAllFALTokens(allFALTokens);
    
        in_stream.close();
    }
    
    The string of a FAL item looks like "1208A4E8".
    Tuesday, February 12, 2013 12:02 AM
  • I've also tried the File access sample but it does not offer app execution state management of FAL feature. For example, when the sample app is reactivated from terminated state, MRU or FAL list is lost.
    Tuesday, February 12, 2013 12:46 AM
  • I think MSFT should fix the issue I reported as soon as possible. If you require developers to save app data when handing suspending event, then you have to provide a mechanism to restore the app data.
    Thursday, February 14, 2013 3:32 PM
  • The File access sample has a bug that it only checks the MRU or FAL lists if a new file has been stored in scenario1, but if you do so or if you bypass the check on rootPage->SampleFile then you will see that the MRU and FAL both persist correctly.

    --Rob

    • Marked as answer by Jesse Jiang Monday, February 18, 2013 6:57 AM
    Friday, February 15, 2013 1:28 AM
    Owner
  • Hi Rob

    I re-study the file access sample and find FAL does persist even after the app is terminated. But I have one more concern, Is FAL shared by other apps running on the system?

    Tuesday, February 19, 2013 3:03 PM
  • No, each app has its own access caches.

    --Rob

    • Marked as answer by Leonard Wednesday, February 20, 2013 2:29 PM
    Tuesday, February 19, 2013 6:19 PM
    Owner