where is my static content in windows phone 8 app? - windows-phone-8

I have Windows Phone 8 app in which I want to include my own 10 MP3s. I included them in /Assets, but a call like
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
songs = store.GetFileNames("*.mp3").ToList();
Console.WriteLine("Found {0} files ", songs.Count());
}
keeps returning that the # of MP3s in my store is 0.
I tried putting the MP3s in Content, Assets, Resources and set Copy Always option, but to no avail.
Any help will be appreciated.

if you set your files as "Embedded Resource", you can get a list of files at runtime.
Here is how you can do this:
Set the Build Action of your files as "Embedded Resource".
Use Assembly.GetCallingAssembly().GetManifestResourceNames() to enumerate the resources names
string[] GetResourcesNames()
{
return Assembly.GetCallingAssembly().GetManifestResourceNames();
}

The files is not copied to isolated store for your app, but you can get them by the uri:
var mymp3file = new Uri("Assets/HomersDoh.mp3", UriKind.RelativeOrAbsolute);

Related

firebase Google Cloud storage download URL has folder name which becomes file name

We are using Firebase Google Cloud Storage Bucket to store our files.
When the logged in user wants the download the file kept inside certain folder
Eg: 123/admin/1469611803143/123.xlsx
The url generated will be
https://firebasestorage.googleapis.com/v0/b/MYWEBSITE.appspot.com/o/123%2Fadmin%2F1469611803143%2F123.xlsx?alt=media&token=whatever_alpa_numeric_token
As I download this file the file name will be 123%2Fadmin%2F1469611803143%2F123.xlsx
and not 123.xlsx
We have tried using download attribute to change the file name
but this did not change the file name to 123.xlsx
Please HELP
I'm pretty new with firebase but I achieved this with the following code :
var storageRef = firebase.storage().ref();
var child = storageRef.child("your path");
var uploadTask = child.put(<file>);
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
function(snapshot){
// HANDLE TASK PROGRESS
},
function(error){
// HANDLE ERROR
},
function(){
// UPLOAD SUCCESSFULL
var newMetadata = {
contentDisposition : "attachment; filename=" + fileName
}
child.updateMetadata(newMetadata)
})
This is (fortunately or unfortunately) intended behavior. Technically, files in Firebase Storage are stored with the full path (so 123%2Fadmin%2F1469611803143%2F123.xlsx is actually the file name--the slashes and percent escaping are part of the name, and are only represented as path separators in the UI), which is how we get this behavior.
We're likely to modify how downloads work in the future (in that we'll truncate the name), but we've been busy fixing other bugs and polishing higher priority pieces.

How to read data files included in the app

For my program I have to include huge index and data files in the program bundle. Because it is an universal app, I have included these files in a folder named "Data" within the "Shared" Project.
Now I try to read:
StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("Data/"+fileName);
Stream stream = (await file.OpenReadAsync()).AsStreamForRead();
BinaryReader reader = new BinaryReader(stream);
Windows.Storage.FileProperties.BasicProperties x = await file.GetBasicPropertiesAsync();
I get a System.ArgumentException "mscorlib.ni.dll" at the first line. What's wrong?
If somebody can help me and I get the file, I want to find the filesize. I hope, I can find this Information within the FileProperties (last line of code).
Then I want to set a FilePointer within that file and to read a defined number of binary data. Can I do that without reading the whole file in memory?
What you are trying to do is to access LocalFolder, which is not the same as Package.Current.InstalledLocation.
If you want to access files that are included with your package, you can do for example like this - by using URI schemes:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(#"ms-appx:///Data/"+fileName));
using (Stream stream = (await file.OpenReadAsync()).AsStreamForRead())
using (BinaryReader reader = new BinaryReader(stream))
{
Windows.Storage.FileProperties.BasicProperties x = await file.GetBasicPropertiesAsync();
}
or like this - by getting file from your Package, which you can access as StorageFolder - also pay attention here to use correct slashes (as it may be a source of exception):
StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(#"Data\" + fileName);
using (Stream stream = (await file.OpenReadAsync()).AsStreamForRead())
using (BinaryReader reader = new BinaryReader(stream))
{
Windows.Storage.FileProperties.BasicProperties x = await file.GetBasicPropertiesAsync();
}
Note also that I've put your Stream and BinaryReader into using, as they are IDisposable and it's suitable to release those resources as they are no longer needed.
Note also that when your shared project has a name MySharedProject, you will have to modify the Path of above URI:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(#"ms-appx:///MySharedProject/Data/"+fileName));
or obtain the suitable StorageFolder:
StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(#"MySharedProject\Data\" + fileName);
One remark after discussion:
When you add a file with .txt extension to your project, its Build Action by default is set to Content. But when you add file with .idx extension, as I've checked, its Build Action is set to None by default. To include those files in your package, change them to Content.
After Romasz has brought me to the right path, I can see the problem is quite different there.
My data files were involved in the correct place in the project, but Visual Studio does not bind all what you want.
In my project I need large data files to be firmly integrated into the program. These are between 13 KB and 41 MB in size and have file types .idx and .dat. These names are part of the problem.
What I know so far:
I may add .txt files with seemingly arbitrary size. Tested with 41 MB - no problem.
The same file with changed file type .idx is not added. The file is simply not included in the compiled project. No error message.
Of course I can rename the .idx files to another file type (tested with .id), but I want to know why idx files are treated differently. And why I got no error indication.

Update Album Art Windows 8.1 Store App

I'm trying to update the album art for a background playing track in Windows 8.1 Store app (C#/Xaml) but although I get no exceptions, the image doesn't update in the little transport popup...
this is the code I'm executing to update it:
var track = App.MediaPlayer.Tag as Track;
await App.Api.Cache.DownloadFile("currentalbumart.png", new Uri(track.medium_image_url));
// Get the updater.
SystemMediaTransportControlsDisplayUpdater updater = App.SystemControls.DisplayUpdater;
updater.Type = MediaPlaybackType.Music;
updater.MusicProperties.AlbumArtist = track.artist;
updater.MusicProperties.Title = track.name;
updater.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appdata:///local/currentalbumart.png"));
updater.Update();
The DownloadFile method executes without any issue, and if I navigate to the local folder, indeed the image does get downloaded. I thought perhaps I'm using the wrong URI to it, but I don't get any exceptions when I assign it to the thumbnail...
what might be wrong here? many thanks
I actually had this problem for ages but finally fixed it today, after about 20+hours on previous apps to get it working. If you use the following code to update your thumbnail, you can use a html link:
updater.thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(new Windows.Foundation.Uri("http://www.example.com/logo.jpg"));
This leaves the full code for the function to be:
//Used to update the media controls etc
function UpdateSongInfoManually(artist,songName,AlbumArtist, SongArt) {
// Get the updater.
var updater = systemMediaControls.displayUpdater;
updater.type = 1; //1=Music
// Music metadata.
updater.musicProperties.AlbumArtist = artist;
updater.musicProperties.AlbumArtist = mixName;
updater.musicProperties.Title = songTitle;
updater.thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(new Windows.Foundation.Uri(MixArt));
// Set the album art thumbnail.
// RandomAccessStreamReference is defined in Windows.Storage.Streams
//updater.Thumbnail =
// RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Music/music1_AlbumArt.jpg"));
// Update the system media transport controls.
updater.update();
}
I have a similar problem in a Windows 8.1 Phone (Store) app. First I tried to copy MP3 files (with ID3 tags) and a folder.jpg file as album art using Windows Explorer to the Phones Music library (Music//). Using standard Music app everything works fine.
Than I tried to do the same inside the app I am developing. I download mp3 and jpg file from a server and stored them into the music library. I verified the result with the phones standard Music App. The ID3 tags are detected correctly but the album art jpg file is not shown. And now the thing becomes completely magic. Using Explorer I copied the jpg file to the PC and checked it. Jpg looks fine. Than I copied it back to the phone. And now standard music app shows correct album art !!
Maybe it has something to do with file security.

How to prevent lost save data when upgrade app on WP8 using cpp

cpp has no IsolatedStorageSettings or IsolatedStorageFile.
so i simply using "FILE" and "fopen" to store a game data.
but when i reinstall or upgrade the apps using "Xapdeploy" or debug with vs.
the save data will lost.
so how can i mark it is as a IsolatedStorageFile.
I mean when I upgrade the app, the file will not deleted by system.
You need to save data in the LocalFolder (new name for Isolated Storage) for it to be persisted.
There are Windows Runtime APIs you can use from C++/CX for this which are probably the best way to go (look for StorageFolder and StorageFile in particular), especially if you want to stay portable with Windows Store apps.
However if you want to use fopen the main issue is that this takes a char[], not wchar_t[] file name that is used by the rest of the platform. To get around this you will need...
void SaveToFile()
{
// get local folder (= isolated storage)
auto local = Windows::Storage::ApplicationData::Current->LocalFolder;
auto localFileNamePlatformString = local->Path + "\\game.sav";
FILE* pFile;
auto f = _wfopen_s(&pFile, localFileNamePlatformString->Data(), L"w");
auto res1 = fprintf(pFile, "123456789");
auto res2 = fclose(pFile);
}

download and decompress a zip file in windows phone 8 application

I am working on a windows phone 8 application (phonegap) which downloads a zip file from my server location, I want to unzip this file in my application at runtime to use the files in the archive.
You can use 3rd party libraries in order to decompress and extract ZIP files in WP7/WP8. The most common one is #ZipLib which you can download the WP7 port from # http://slsharpziplib.codeplex.com/
My personal favourite library is DotNetZip which is a superset of #ZipLib and much more stable IMO. Here's a quick code sample:
private void MyExtract()
{
string zipToUnpack = "C1P3SML.zip";
string unpackDirectory = "Extracted Files";
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
// here, we extract every entry, but we could extract conditionally
// based on entry name, size, date, checkbox status, etc.
foreach (ZipEntry e in zip1)
{
e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}
}