Add Tesseract to the output directory C# - c#

This is starting to annoy me. I have a UWP that allows you to open up a separate windows forms app to take advantage of tesseract. The app works fine when running on its on, however as soon as I call upon it to run using the UWP, the app crashes and gives me the error that it could not find the file specified, that file being the tesseract folder. I have it referenced within the app as
var path = "C:\\Users\\dan\\source\\repos\\TesseractApp\\packages\\Tesseract.4.1.1";
Is this something really simple I'm missing? If anything I'd like to copy the Tesseract.4.1.1 folder to directory, but that doesn't seem to work either. Hopefully this is clear.
EDIT - I believe it is just the exe file not working properly. I think I'm not copying over enough files into the Assets folder of the UWP and the exe of the tesseract app does not have what it needs to work.

Related

Reference (text) files in compiled MacOS app (application file)

I'm working with Avalonia to create a MacOS desktop program using c#. I can run the program locally or output it to a final app file using dotnet.bundle. Attached image shows the contents of the app file using Mac's "show package contents".
There are files that are deployed to the app bundle that I would like to read when running the app, but don't know how to reference them. Since this is in C#, I can't find any docs similar to what apple provides here https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html#//apple_ref/doc/uid/10000123i-CH104-SW1
I've tried referring to the parent directory, but this only works in design time.
I've tried a variety of syntax including Environment.GetCurrentDirectory as prefix to the below path.
string path = "Repository/CreateTables.sql";
string assets = File.ReadAllText(path);
Thanks
Thanks for the tip, yes I have been trying to print out paths but oftentimes they were blank when run from the .app (for example, Environment.CurrentDirectory returns ""). I did find a way to get at the path here https://github.com/AvaloniaUI/Avalonia/issues/5443#issuecomment-775906396, and it was not the path I was expecting. I thought the location of the file would start at myapp.app, but you need the path to myapp.app as well.
/Applications/MyApp.app/Contents/MacOS/Repository/CreateTables.sql

Access to an embeded resource file doesn't work on Xamarin but on Windows App

I added an excel File (template.xlsx) to the project resources as an embedded resource. In my code I want to save that file to disk.
On Windows it works well with:
File.WriteAllBytes("test.xlsx", Properties.Resources.template);
But in my Xamarin.Forms project exactly the same line does not work because "Properties" is unknown in the current context.
I searched half a day in the net but all hints I got don't work either or confuse me even more. It seems I am missing an essential piece of base knowledge here. Could somebody tell me if I can easily access an embeded File in Xamarin similar like I do on Windows?
The difference I can see in the two test projects is:
In the project explorer of the windows project I can see Properties->Resources.resx. However, the template file is not located there but in Resources->template.xlsx
In the project explorer of the Xamarin project there is no Resources.resx in the Properties folder.
My file is again located under Resources->template.xlsx
You have to read that file in your code and then use it to write that file to file storage (application sandbox) of the platform. You can save files to that location, although you may not easily be able to access that file outside the scope of the app (say from another application).

Is it possible to have a Resource folder in a published C# project?

I have a question which will probably be quite vague.
I'm developing a Windows Forms application in C# that can read and write games to an Access database. Every game has an attribute that links to an Image in the resource folder.
While debugging I was able to just read and write my screenshots to the following path:
"..\\..\\Resources\\Screenshots\\";
I tried publishing my application earlier today to test if it would still work and if not, to locate the path where the Resource folder would be when published.
So far I have the feeling that the resources just get burned into the exe file or one of the other files it generates.
Is it in any way possible to have a real folder in the published version of an application from which I can keep reading and writing my images like I did while debugging?
Thanks in advance.
Yes your screenshots will be compiled into the assembly as resources when publising.
As for the real folder, you can absolutely do that. Make sure you give your app the right path to that folder.

XML saved by application installed in Program Files: where is it?

I've spent the last two hours Googling on this with no results, so…
I am developing an application which uses XML files to save data. These files are supposed to exist in the same directory as the program executable. I use:
string filePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\xml\\filename.xml";
It works.
I've created the installation file in Inno Setup. This works as well, copying my XML files exactly where I want them to go.
I open my application directly from the installation folder, from the Start menu icon, from a desktop shortcut, and it works fine.
I make some changes to my program, then I close it and start it again. Everything is fine: all the saved changes are read back from the XML.
But then I open the specified XML file and there are no changes!
I wouldn't bother as at least it's working, but:
When I uninstall the application then install it again to the same directory, changes made to the previously installed file are still there!
I'm very curious to know what's happening.
This only happens if the program is installed to Program Files. If I install it to My Documents, changes are shown in the XML files and after reinstalling it the default settings are restored as expected.
My questions are:
Where are those XML files being stored, and how can I load it if the specified path points to Program Files and they are not there?
Obviously, how do I fix it?
EDIT
Finally found those files in C:\Users[USERNAME]\AppData\Local\VirtualStore\Program Files[APPNAME]
Check what is saved into your local application data folder (it's \Users[USERNAME]\AppData\Local\ for Windows 7).
It looks as if your app didn't have rights to save things in your ProgramFiles folder and saved it where it could, probably in this location:
String appData =
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
Also you may try running your application as administrator and check if changes to your xml data still doesn't show.
Cant you print out the value of
System.IO.Path.GetDirectoryName(Application.ExecutablePath)
then you should be able to see where your xml files are stored, if it is a console application just use Console to print if it is WPF print it to a label or something

Image.Save to relative path doesn't save where expected

The documentation doesn't explain the behavior when passing in a path such as "myFile_temp.jpg" but I would assume that it would save the the application directory because this is a relative path, relative to the application we are currently running.
I think that the problem can be solved by prepending the current application directory to my temp file name using
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
Sure there are lots of ways to do it, but this should work.
My issue is I'd like to know why this is happening rather than just throw a patch on it and ship it back out to the users.
Code is WPF, C# project compiled with .NET 4.0 and Visual Studio 2010 and runs on a lot of different machines. Mostly 32-bit XP,while the dev machine is a 64-bit Windows 7.
Can any one explain this behavior and why it's occuring?
Edit
The files will on occasion be saved to the directory the user selected files from to manipulate. They resize them, the program keeps track of the size percent for each of the file paths. When the user is finished they will click done and the program will go through each of the file paths, create a copy, resize the image and then save it with a _temp on the end.
Take note that it doesn't always do it and it when it does it doesn't do it for all the files they touched.
It works as s expected. You just didn't expect valid behavior. Lets assume that your app is placed in c:/superapps/myapp.exe. You opened command line and you're in C:\ which means that this your current working directory.
You can still run your app by ./superapps/myapp but your working directory is still C:\. And this will be working directory of your app in this case, not the directory you placed the binaries.
That is why it may not have permission or save data in some unexpected by you location. You should always think that your app could be run just like any other command like dir. It will be working in the place where user is currently standing (his current working dir) not in the place it's binaries are stored in

Categories

Resources