download and decompress a zip file in windows phone 8 application - windows-phone-8

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);
}
}

Related

Accessing ArcGIS Pro geoprocessing history programmatically

I am writing an ArcGIS Pro Add-In and would like to view items in the geoprocessing history programmatically. The goal of this would be to get the list of parameters and tools used, to be able to better understand and recreate a workflow later, and perhaps, in another project where we would not have direct access to the history within ArcGIS Pro.
After a lot of searching through documentation, online posts, and debugging breakpoints in my code, I've found that some of this data does exist privately within the HistoryProjectItem class, but since this is a private class member, within a sealed class it seems that there would be nothing I can do to access this data. The other place I've seen this data is less than ideal, with the user having an option to write the geoprocessing history to an XML log file that lives within /AppData/Roaming/ESRI/ArcGISPro/ArcToolbox/History. Our team has been told that this file may be a problem because certain recursive operations may cause the file to balloon out of control, and after reading online, it seems that most people want this setting disabled to avoid large log files taking up space on their machine. Overall the log file doesn't seem like a great option as we fear it could slow down a user by having the program write large log files while they are working.
I was wondering if this data is stored somewhere that I have missed that could be accessed programmatically from the add-in. It seems to me that the data within Project.Items is always stored regardless of user settings but appears to be inaccessible this way to due class member visibility. I'm unfamiliar with geodatabases and ArcGIS file formats to know if a project will always have a .gdb which perhaps we could read the history from there.
Any insights on how to better read the Geoprocessing history in a minimally intrusive way to the user would be ideal. Is this data available elsewhere?
This was the closest/best solution I have found so far without writing to the history logs that most people avoid due to filesize bloat, and warnings that one operation may run other operations recursively causing the file to balloon massively.
https://community.esri.com/t5/arcgis-pro-sdk-questions/can-you-access-geoprocessing-history-programmatically-using-the/m-p/1007833#M5842
it involves reading the .arpx file (which is written to on save) by unzipping it, parsing the XML, and filtering the contents to only GPHistoryOperations. From there I was able to read all the parameters, environment options, status, and duration of the operation that I was hoping to gain.
public static void ListHistory()
{
// this can be run in a console app (or within a Pro add-in)
CIMGISProject project = GetProject(#"D:\tests\topologies\topotest1.aprx");
foreach(CIMProjectItem hist in project.ProjectItems
.Where(itm => itm.ItemType == "GPHistory"))
{
Debug.Print($"+++++++++++++++++++++++++++");
Debug.Print($"{hist.Name}");
XmlDocument doc = new XmlDocument();
doc.LoadXml(hist.PropertiesXML);
//it sure would be nice if Pro SDK had things like MdProcess class in ArcObjects
//https://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#MdProcess.htm
var json = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented);
Debug.Print(json);
}
}
static CIMGISProject GetProject(string aprxPath)
{
//aprx files are actually zip files
//https://www.nuget.org/packages/SharpZipLib
using (var zipFile = new ZipFile(aprxPath))
{
var entry = zipFile.GetEntry("GISProject.xml");
using (var stream = zipFile.GetInputStream(entry))
{
using (StreamReader reader = new StreamReader(stream))
{
var xml = reader.ReadToEnd();
//deserialize the xml from the aprx file to hydrate a CIMGISProject
return ArcGIS.Core.CIM.CIMGISProject.FromXml(xml);
}
};
};
}
Code provided by Kirk Kuykendall

Adobe Air URLRequest to Local File Works Windows 7, Not 10

I developed an Adobe Air App for a small intranet. All computers have been running Windows 7, but now are beginning to be replaced with Windows 10 systems. I can access the mapped drive "I" and the local "C" drive using the file class on Windows 7 machines, but only the mapped drive "I" on Windows 10.
Edit: Capabilities.localFileReadDisable returns false on both Windows 7 and Windows 10 systems.
****I could bypass the need for the local file if Air could get any specific information about the machine it is running on, serial number, mac address, computer name, etc. It really makes no difference what information I get, it just has to be unique to that computer. And using cookies isn't an option because they are volatile****
The following code accomplishes two things.
First, it displays the running version of the Air file and looks for a file on a mapped drive with the latest version available. If they are the same, the computer is running the latest version. If they aren't the same, the new version is displayed to the user, indicating the app should be updated.
Second, it grabs the name of the specific computer from a text file residing on the local drive. That name is used on reports to indicate which computer was being used. There is probably a far superior way to accomplish this, but on Windows 7, it works perfectly for me. Unfortunately, Windows 10 throws an error when trying to access the file on the local drive.
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///C:/machineName.txt
Any help would be greatly appreciated.
var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = appXML.namespace();
version_txt.text = "V"+appXML.ns::versionNumber;
// Define path to the version number
var updatePath:URLRequest = new URLRequest("file:///I:/air/update.txt");
// Define path to name of specific pc
var machineName:URLRequest = new URLRequest("file:///C:/machineName.txt");
// Define the URLLoaders
var updateLoader:URLLoader = new URLLoader();
function checkUpdate():void{
updateLoader.load(updatePath);
}
var nameLoader:URLLoader = new URLLoader();
function checkName():void{
nameLoader.load(machineName);
}
// Listen for when the file has finished loading.
updateLoader.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(e:Event):void
{
// The output of the text file is available via the data property
// of URLLoader.
if(Number(appXML.ns::versionNumber)<Number(updateLoader.data)){
update_txt.text = "UPDATE TO V"+updateLoader.data;
}
}
nameLoader.addEventListener(Event.COMPLETE, nameComplete);
var name_txt:String = new String;
function nameComplete(e:Event):void{
name_txt = nameLoader.data;
var holder:String = version_txt.text;
version_txt.text = name_txt+" ** "+holder;
}

How to store user data in window phone 8 app?

Please help me how to store user data in window phone 8 application?
I have a plan to develop an application on windows phone 8 which allow user create xml file to store their private data. The question is how to store user data on window 8.1 phone. After search solution, i know that
+ Isolated Storage can store data but it just small data for application
+ Store data on SD card is read only.
So, is there any other way to store data?
Thank and sorry about my english skill!
ApplicationData (LocalFolder on WP8 or LocalFolder and RoamingFolder on WP8.1) is designed for what you are trying to do. The ApplicationSettings themselves are better for small pieces of data, but apps can save files of any size which the phone has room for in the LocalFolder.
See Accessing app data with the Windows Runtime on MSDN for details. While the docs target Windows Runtime apps, the ApplicationData and StorageFile API are available to Silverlight apps on Windows Phone 8 and later.
Additional Usings:
using System.Xml.Serialization;
using Windows.Storage;
using System.IO;
Code:
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile saveFile = await localFolder.CreateFileAsync("data.xml", CreationCollisionOption.ReplaceExisting);
using (var ras = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
{
Stream stream = ras.GetOutputStreamAt(0).AsStreamForWrite();
XmlSerializer serializer = new XmlSerializer(typeof(List<Book>));
serializer.Serialize(stream, data);
}
If you need more structured data than XML then you can store a SQLite database in the local folder. If you need more space than is reasonable for an app to store on the device then you'll need to move it to a web service. Azure Mobile Services is a good place to do that. You can call such a service from a Windows Phone Silverlight app, but the wizards will generate Universal apps.

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);
}

where is my static content in windows phone 8 app?

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);