Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- writeTextAsync = (path, text) ->
- # First try if an existing file can be written
- Windows.Storage.PathIO.writeTextAsync(path, text)
- .then null, (error) ->
- [_, folder, subFolders, fileName] = /^ms-appdata:\/\/\/(temp|local|roaming)\/(.+?)\/([\w]+\.?\w+)$/.exec(path)
- folder = "temporary" if folder is "temp"
- createSubFolders = subFolders.split("/").reduce((promise, folderName) ->
- promise = promise.then (folder) ->
- folder.createFolderAsync(folderName, Windows.Storage.CreationCollisionOption.openIfExists)
- , WinJS.Promise.as(Windows.Storage.ApplicationData.current["#{folder}Folder"]))
- createSubFolders.then (folder) ->
- folder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.openIfExists)
- .then (file) ->
- Windows.Storage.FileIO.writeTextAsync(file, text)
- writeTextAsync("ms-appdata:///temp/apifail/file.txt", "This is how Windows.Storage.PathIO.writeTextAsync should have worked in the first place")
- .done null, (error) ->
- logger.error("Could not write file")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement