Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. writeTextAsync = (path, text) ->
  2. # First try if an existing file can be written
  3. Windows.Storage.PathIO.writeTextAsync(path, text)
  4. .then null, (error) ->
  5. [_, folder, subFolders, fileName] = /^ms-appdata:\/\/\/(temp|local|roaming)\/(.+?)\/([\w]+\.?\w+)$/.exec(path)
  6. folder = "temporary" if folder is "temp"
  7.  
  8. createSubFolders = subFolders.split("/").reduce((promise, folderName) ->
  9. promise = promise.then (folder) ->
  10. folder.createFolderAsync(folderName, Windows.Storage.CreationCollisionOption.openIfExists)
  11. , WinJS.Promise.as(Windows.Storage.ApplicationData.current["#{folder}Folder"]))
  12. createSubFolders.then (folder) ->
  13. folder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.openIfExists)
  14. .then (file) ->
  15. Windows.Storage.FileIO.writeTextAsync(file, text)
  16.  
  17. writeTextAsync("ms-appdata:///temp/apifail/file.txt", "This is how Windows.Storage.PathIO.writeTextAsync should have worked in the first place")
  18. .done null, (error) ->
  19. logger.error("Could not write file")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement