Files

Windows 8.1 brings enhanced support for in-app file management, new ways to interact with user content through libraries, and the ability to push your app’s unique content to the Windows index. This means that your app can easily access user content and make its own content easier for other apps to discover.

New or updated in Windows 8.1

File picker updated to support new app display modes

[Get the File picker sample now.]

In Windows 8.1 the file picker can be called by apps running in split-screen and full-screen display. This helps your users work and multitask they way they want to. For example, if a user has a Skype conversation open in one window and their email app open in the other, the email app can open the file picker for the user to include an attachment without the having to go to a full-screen display. To learn more about using the file picker, see Quickstart: Accessing files with file pickers.

In-app management of user libraries

[Get the Library Management sample now.]

Windows 8.1 introduces the StorageLibrary class, which lets users manage folders within their personal libraries (like Music and Videos) from within an app. This is especially useful in media-gallery apps, where users often want to expand their collections by adding folders that contain more of their images, music, or video.

This is all made possible by a specialized file picker, called using StorageLibrary methods, that lets users add folders to their libraries. Users no longer have to exit your app and go to the desktop to expand their media collection.

Retrieving parent files or folders

[Get the File access sample now.]

The storage APIs for Windows 8 didn't define a method for retrieving the parent folder of a storage item directly, so you had to write your own custom logic. In Windows 8.1, you can use the GetParentAsync method to get the parent StorageFolder of a file or folder.

Important  For the GetParentAsync method to succeed you must have access to the parent, either by declaring library capabilities or by persisting a higher-level folder in the future-access List. Also, instead of raising an exception, this method returns null if you can’t get to the parent.

Comparing files with IsEqual

[Get the File access sample now.]

The storage APIs for Windows 8 didn't define a method for directly comparing storage items to determine whether they represent the same item. Developers worked around this issue by comparing paths, but they still encountered items that didn't have path values. In Windows 8.1, you can use the IsEqual method to determine whether two storage items represent the same file.

The following example shows you how to compare two storage files for equality by using the new method.


function openNewFile() {
    var picker = new Windows.Storage.Pickers.FileOpenPicker;
    picker.fileTypeFilter.replaceAll(["*"]);
    picker.pickSingleFileAsync().then(function (file) {
        var alreadyOpenedFile = null;
        _openFiles.some(function (openFile) {
            if (file.IsEqual(openFile.file)) {
                alreadyOpenedFile = openFile;
                return true;
            }
            return false;
        });

        if (alreadyOpenedFile != null) {
            alreadyOpenedFile.window.activate();
        } else {
            createNewFileViewerWindow(file);
        }
    });
}


New KnownFolders properties

Windows 8.1 introduces two new KnownFolders properties that let you access files in two additional locations: CameraRoll and Playlists.

The KnownFolders.CameraRoll property lets you access pictures taken using the device camera—just like the existing Windows Phone 8 property. The KnownFolders.Playlists property lets you access the user's playlists.

File retrieval without error-handling requirements

[Get the File access sample now.]

Windows 8.1 introduces the StorageFolder.TryGetItemAsync method, which lets your app try to retrieve a file or folder by name without having to add error-catching logic in the app code. If the file or folder can't be found, TryGetItemAsync returns null and does not throw an exception. Because the method returns null, you can also use it determine whether the specified fie or folder exists.

Exposing view files in Open (With) scenarios

In Windows 8.1, you can use the NeighboringFilesQuery property to enable navigation to the files near the file that an app was activated for.

In Windows 8, the default app for opening content with a specific file association gets an object that represents only the invoked file. This can be a problem for media gallery apps, in which users expect to navigate to neighboring files. In Windows 8.1, the default app can get the collection of files in the surrounding view—that is, the collection that the invoked file was selected from.

Your app needs to declare a specific library capability to get items of the corresponding type. For example, to get pictures in the NeighboringFilesQuery, your app must declare the Pictures library capability.

This example shows how to retrieve a collection of files that are neighbors to the file that activated an app.


function activated(sender, e) {
    if (e.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.file && e.files.size > 0) {
        var invokedFile = e.detail.files[0];
        var neighboringFiles = e.detail.neighboringFilesQuery;
        if (neighboringFiles) {
            result.neighboringFiles.findStartIndexAsync(e.detail.files[0]).done(function (index) {
                var invokedFileElement = document.getElementById("invokedFile");
                invokedFileElement.textContent = "Invoked item: " + invokedFile.name + ", at index " + index + " in view file enumeration.";

                var prevFileslist = document.getElementById("prevFilesList");
                result.neighboringFiles.getFilesAsync(0, index).done(function (fileList) {
                    fileList.forEach(function (file) {
                        // Create an entry in the list for the file.
                        var fileItemElement = document.createElement("li");
                        fileItemElement.textContent = file.name;
                        prevFileslist.appendChild(listItemElement);
                    });
                },
                function (error) {
                    // Handle error trying to get list of files.
                });

                var nextFileslist = document.getElementById("nextFilesList");
                result.neighboringFiles.getFilesAsync(index + 1, -1).done(function (fileList) {
                    fileList.forEach(function (file) {
                        // Create an entry in the list for the file.
                        var fileItemElement = document.createElement("li");
                        fileItemElement.textContent = file.name;
                        nextFileslist.appendChild(listItemElement);
                    });
                },
                function (error) {
                    // Handle error trying to get list of files.
                });
            },
            function (error) {
                // Handle error trying to get file index.
            });
        }
    }
}

app.addEventListener("activated", activated);


Adding app content to the Windows index

[Get the Indexer sample now.]

In Windows 8.1, your app content can be added directly to the Windows index. Adding content to the index ensures that app content can be searched quickly with queries of the ApplicationIndexedContent folder or by using the new in-app search control. You can add file properties and content to the index either by using the new API set in Windows.Storage.Search, or by creating "appcontent-ms" files.

OneDrive

In Windows 8.1, OneDrive offers two new feature updates:

  • File storage

    It is now very easy for any user with an Microsoft Account (MSA) to navigate to OneDrive in the file picker and select files or folders to open in your app.

  • OneDrive storage management tool

    We have improved the OneDrive storage quota-management experience on Windows 8.1. Users can manage OneDrive right from within Windows. They can view their storage usage, upgrade their storage plan, and reclaim space on OneDrive all without leaving the native Windows 8.1 interface.

DDS image file support

The Microsoft DirectDraw Surface (DDS) file format is now supported in Windows Store apps using JavaScript and the Extensible Application Markup Language (XAML) WebView control, letting you create WebGL apps that run fast even with large textures.

About block compression and DDS

Block compression (BC) is a class of compression that is used to store pixel data in a DirectDraw Surface (DDS) file. Unlike other image file formats, graphics processing units (GPUs) can directly sample from block compression formats without any decompression or processing, improving the performance of loading texture resources in Windows Store apps. BC formats use an average of 4 - 8 bits per pixel, while a typical RGBA texture uses 32 bits per pixel. As such, block compression formats also reduce overall GPU memory usage by up to 87.5%, allowing larger number of assets or higher quality assets to be used in Windows Store apps.

While there are a number of block compression algorithms, Windows Store apps using JavaScript and the XAMLWebView control on Windows 8.1 only support three types of block compression in the DDS file format: BC1, BC2, and BC3. Block compressed DDS images will load much faster than JPEG images, as there is almost no CPU decode time, and you can use more texture resources, as block compression uses less GPUs memory. Block compressed DDS files are the ideal image format for inbox game backgrounds and textures.

How to use Block Compression in DDS files

When creating converting your image assets to block compression format in Windows Store apps using JavaScript or XAMLWebView control, you will need to consider the following restrictions:

  • Only BC1, BC2, and BC3 block compression formats are supported, corresponding to the following DXGI_FORMAT enumeration values:

    • DXGI_FORMAT_BC1_UNORM
    • DXGI_FORMAT_BC2_UNORM
    • DXGI_FORMAT_BC3_UNORM
  • Premultiplied alpha must be used. Both legacy DDS files using formats that explicitly define premultiplied alpha (DXT1, DXT2, DXT4) and new DDS files that use the DDS_HEADER_DX10 structure with a valid DDS_ALPHA_MODE value (DDS_ALPHA_MODE_OPAQUE and DDS_ALPHA_MODE_PREMULTIPLIED) are supported.

  • The X and Y dimensions must be multiples of 4 pixels.

  • Volume textures, cubemaps, mipmaps, or texture formats in DDS are not supported.

If you do not follow these restrictions, your DDS file will not load in Windows Store apps using JavaScript or XAML WebView control. For more information, see this link.

Once you have created a block compressed asset in a DDS file, you can load the DDS file in markup or through JavaScript:

HTML

<img src=”sample.dds” />

JavaScript

var img = new Image();
img.src = “sample.dds”;

For more info about block compression and the DirectDraw Surface file format, see block compression, Programming Guide for DDS and the Reference for DDS.

When to use Block Compression Formats

As mentioned above, block compressed DDS files are great for improving the number of large textures you can use in your Windows Store app and improving how quickly your app loads. However, even though block compressed DDS files are more efficient in terms of GPUs memory usage, they consume more space on disk compared to JPEG. Block compressed DDS files are best used as a local asset in your application package, and are not the ideal format for downloading over the network. While block compressed DDS files are supported on Internet Explorer 11, due to the higher network cost, using this format on the web is not recommended.

As the block compression format is lossy, just like with other lossy formats, you must ensure that visual quality is not compromised when converting to block compression. Block compression performs very well with real world "natural" images, but can produce artifacts for sharp gradients and color shifts.

 

 

Show:
© 2014 Microsoft