App translations are not working after downloading it from Store - c#

I am having a problem where my app translations work on my pc when I set different language with ApplicationLanguages.PrimaryLanguageOverride, but after the same app is uploaded into Microsoft Store and downloaded from there - translations stop working. As a default it uses English language and ignores other selected languages.
Any idea why?

If you are generating an app bundle during Store package creation, the language-specific resources, different image scaling options, etc. are exported to separate packages to minimize the app package size that has to be downloaded by the user. This however means, that the system will download only the languages it deems required. So if you don't add the target language in the list in the Region & Language area of system settings, it won't probably be downloaded as part of the app package and hence switching to it manually using PrimaryLanguageOverride will have no effect. However note that when you add the language, the system will later download the language-specific resources automatically from the Store, so it will then be available.

Related

Saving file in arbitrary folder uwp

I'm writing UWP app (C# and C++/CX).
My app gives user an opportunity to save video recorded by some connected camera.
I use OpenCV VideoWriter for it because I have to add video effects to C# SoftwareBitmap (comes to me from MediaFrameReader).
Thats how I'm creating VideoWriter in C++/CX code:
videoWriter.open(
pathToCreatedFile, // Works with "videos", but not with "desktop" or other
encodingProperties.codec,
encodingProperties.fps,
cv::Size{ (int)frameSize.Width, (int)frameSize.Height }
);
If I pick default Windows "Videos" library for saving, everything is good, but when I try to use "Desktop" folder for example or any other specific location, my output .mp4 file is 0KB.
Is it possible to save file in random directory in UWP and how can I reach it?
P.S. My minimal version is November update.
By design, you don't have access to arbitrary file folders from a UWP. You can request specific media libraries via a declared capability easily: documentsLibrary, documentsLibrary, picturesLibrary, and/or picturesLibrary.
There is no option for accessing the desktop directly.
The broadFileSystemAccess capability would allow this, but this is a restricted capability which means it will be difficult to publish it to the Windows Store (if that's your plan).
See Microsoft Docs.

How to hide your files from user in C#

I designed an application which reads alphabets from text files placed in debug folder and displays them on dot matrix screen. I want to keep the Text files confidential, Is there any way to distribute my application while keeping the files and folder inside "bin" hidden. One way that i can think of is to encrypt the data , but it's not an efficient solution for me as there are around hundred files. Any kind of suggestion will be helpful
Thanks !!
The approach would vary depending on the type of application (web, desktop, mobile, etc.). Assuming this is a desktop application...
You could embed the resources then attempt to use an obfuscator (example Redgate's SmartAssembly) to increase the level of difficulty of decompiling your application o access the file(s). Some obfuscator tools (example Crypto Obfuscator For .NET) allow for encryption signed with certificates to increase the level of security.
Note that embedding and obfuscating is not guaranteed but depending on your average user, and the importance of the files, it may be just enough.

How Can a Web Page Display What Version a File is In Program Files Directory?

How Can a Web Page Display What Version a File is In Program Files Directory?
For example, if I wanted to send a user a URL that would show the user what version of our software is installed (version number and release date) on their Windows PC. I'm just talking about file properties, not actually running something.
Is there a way to do this with .Net/ASP.Net?
The answer is no.
The best you can do with HTML5 or Javascript is to let the user select a file and even then you have very limited access to properties (at most name, size and type) without having the user upload the file.
The most efficient solution right now would be to serve a very basic clickonce application which would locate the files, read the properties and send the information back to the server. From there you can choose to redirect the user back to your website with the information you collected.
Generally access to the Programm folder is limited at best. There used to be a time when we even would write data like Configuration files there. That was Windows 95/98. And it was frowned upon back then.
With the introduction of NTFS with Windows NT (and later XP in the Consumer area), enforceable rules were put in place. Rights tend to be highly limited. This is even more true of Webservers, as they tend to be prime targets for hacking. The only rights you can expected a Webserver to have is read rights to it's programm and the content directory. Maybe if the admin is really nice and it really helps with performance, it might have write rights on a Temporary subfolder of Contents.
Reading out your version from a file is propably possible with only read rights, but not the right way. Usually you just let the compiler hardcode (insert as constant) whatever Version is given in the Project file or by the Version Tracking Software.
So the first thing is that you need some approach of Version Control. And then your answer depends "however this Version control mechanism does tracking of the Compiled version". There is some limited version tracking support in Visual Studio itself. But there is also full, 3rd party Version tracking Software.

Multiple language support in Universal App

This is not a question about standard localization - I know how to localize the app, use resources, Uid's and so on - this works perfectly.
The problem is that the app comes within a bundle, therefore when the user installs the app it covers only languages that are selected in device/phone settings. But I would like to provide an option in settings that would allow choosing a language regarding the settings. For this purpose, I can use ApplicationLanguages.PrimaryLanguageOverride, which works very nice when deployed via VS, but as I've mentioned - version from the store lacks resources, as not all are installed.
Does anybody know how to bypass this bundle behavior?
The problem is also that I'm using MAT (multilingual app toolkit) and my translation comes with xliff files. I've spent quite a lot of time to find a way to convert them to resw files, without success. Is there any way to do it (or I've to write my own converter)?
You need to use ResourceContext:
var context = new ResourceContext(); // deliberately not using getForCurrentView()
context.Languages = new string() {"fr-fr"};
ResourceMap resourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
String str = resourceMap.GetValue("string1", context).ValueAsString;
More info at:
'How to load string resources' and
'ResourceContext class'ResourceContext class'.
PS. I have app in store and there is no problem with changing language without reinstall so all resources must be there
Check out this: UWP: Resource file for languages is not deployed correctly you need to get rid of bundle in order for my code from above to work. Or you could check if chosen language is installed in OS and if not you could not allow user to choose it using:
Windows.System.UserProfile.GlobalizationPreferences.Languages

Writing USB Drive Portable Applications in C#

One of my favorite things about owning a USB flash storage device is hauling around a bunch of useful tools with me. I'd like to write some tools, and make them work well in this kind of environment. I know C# best, and I'm productive in it, so I could get a windows forms application up in no time that way.
But what considerations should I account for in making a portable app? A few I can think of, but don't know answers to:
1) Language portability - Ok, I know that any machine I use it on will require a .NET runtime be installed. But as I only use a few windows machines regularly, this shouldn't be a problem. I could use another language to code it, but then I lose out on productivity especially in regards to an easy forms designer. Are there any other problems with running a .NET app from a flash drive?
2) Read/Write Cycles - In C#, how do I make sure that my application isn't writing unnecessarily to the drive? Do I always have control of writes, or are there any "hidden writes" that I need to account for?
3) Open question: are there any other issues relating to portable applications I should be aware of, or perhaps suggestions to other languages with good IDEs that would get me a similar level of productivity but better portability?
1) There shouldn't be any problems
running a .NET app from a flash
drive.
2) You should have control of
most writes. Be sure you write to
temp or some other location on the
hard drive, and not on the flash
drive. But write-cycles shouldn't be
a problem - even with moderate to heavy
usage most flashdrives have a life
time of years.
3) Just treat it
like's it any app that has xcopy
style deployment and try to account
for your app gracefully failing if
some dependency is not on the box.
If you want to use com objects, use reg-free com and include the com objects with your program.
You should always have control of your writes. Applications should be loaded into RAM at startup, and then memory past that is allocated in RAM, so nothing is written to the flash drive.
The most important thing for a portable application is that basically no installation is necessary for your application. You do not want to be dependant on registry values especially, since your application will not be 'installed' on other computers.
One of the issues with portable applications you may consider is data persistence. Generally, you write to a user's Application Data folder to save data. If this is the case, any data saved will only apply to the user on that computer. If you want some local application data, you may wish to create a Seralized XML file for your settings and store it locally within your application's directory. This file writing would then likely be the only write actions you'd need to worry about.
For your .NET portability issue, you could also write a small entry program in C++, which checks if the computer has .NET installed. .NET has registry values you can check to see the versions installed, so if .NET is installed, run your application, else display a message stating that .NET needs to be installed first.
Edit: I'd like to add that I do application development for Ultrasound machines using XAML in C# 3.0. The application I write works perfectly from a USB Flash Drive, while all user settings are stored on a local AppData basis, so nothing is written to the USB. While the application can be installed through an .exe installer, the installer does not write any registry values the application depends on.
I don't really have answers for #1 or #3. But for #2, the .NET CLR shouldn't be writing to an app's "installation" folder (i.e. the flash drive) unless your code specifically tells it to or is using and modifying file-based settings (ini, xml, etc) that live with the app.
Number 1 is really the kicker if you're not just writing things for personal use. Obviously hosting a portable copy of the full CLR on the thumb drive is impossible. But there are tools that can scan your assembly for its dependencies and package them up into a standalone .exe so that the CLR doesn't necessarily need to be installed on the target system.
I don't actually have any experience with this so it might be best to take what I say with a pinch of salt. But here is my take on it:
You don't need to do anything special.
It is not really a consideration of an application developer as to how and when writes are made to a drive, that is something that is far better controlled by the OS. I know that Windows caches writes to USB drives so I would trust it do handle that.
The only thing you need to consider is that your application will not be installed. So you need to make sure that you design it to run entirely self contained within the directory it is deployed to. You could optionally also make some writes to the users home directory but this needs to be done through the appropriate environment variables.
I would get writing and see if there is anything special about a flash drive that the OS doesn't handle.

Categories