How to Move or Copy/Paste Files on Android - c#

I've searched through the internet for how to move or copy'n'paste files on an Android device programmatically, but i found nothing up to now. what i wish to do is, that my application copies or moves a SQLite Database from the internal sdcard to the app folder in /data/data/example. i would be pleased if someone could explain my how to do that or give me a link to somewhere it gets explained.

A quick search on Stackoverflow turns out two questions with helpful answers:
How to make a copy of a file in android?
Android file copy
Basically, they suggest to read the contents of one file and write those to another file. You can do the same with monodroid.

Related

How can Unity ignore FMOD Cache files when syncing with PlasticSCM?

My dev team is having an issue when trying to add certain files to the ignore.conf file for PlasticSCM. When we try to add the FMODStudioCache.asset and fmod_editor.log, among other FMOD related files, to this config file, they just continue to appear in Unity when receiving pushes and readying a push locally.
It has become very annoying to deal with because it doesn't seem to work as it is intended to. See below the lines we have tried to prevent it from showing up.
**/Assets/Plugins/FMOD/Cache/Editor/FMODStudioCache.asset
**/Assets/Plugins/FMOD/Resources/FMODStudioSettings.asset
fmod_editor.log
# Ignore the Cache folder since it is updated locally.
/[Aa]ssets/Plugins/FMOD/Cache/*
[Aa]ssets/Plugins/FMOD/Cache/*
Assets/Plugins/FMOD/Cache/*
Image link of Unity PlasticSCM with
Sorry, I don't have enough posts yet so it makes me use a link above!
Has anyone found a solution to this? We have tried to even add the files to the hidden config file too and that doesn't work either... Thanks in advance !
Edit: Spelling error in question.

How to store txt file (reading/writing) and build for Android

I'm making a game about questions shared between people, and I want to add natively some questions to the game. In the way I made this game, I need to store a text file in Unity, that contains on each line information about these questions. I need to read and write on that txt file at runtime.
So I basically made a file questions.txt in the Resources folder, and it's actually fine in the Unity Editor: I can write and read as I want.
However, when I tried on my android device, the txt file couldn't be found.
I read that it's because the Resources folder isn't built on android.
Then, I'm lost. I've read about TextAsset, but it's read-only. I Couldn't find a way to make this work with Application.dataPath and Application.persistentDataPath, because the file is actually not created with some script.
That's why I'm asking for some help now. I'm a bit lost and I just want some hints on how to implement that.
Thanks for taking some time to read and help. :)
I figured out how to, in my case at least.
Made a script that contains a public TextAsset. I assigned my questions.txt to that TextAsset through the inspector.
TextAsset is read-only. But here is the tip: I completly copied the content of that file to another that I created in Application.persistentDataPath, which allows reading and writing.
Then, if I want to add native questions the game, all I need to do is copy the lines I need from the TextAsset I can modify before building.
Thanks to #blackapps for the little hint. Solved!

visual c# button opens file without specifying drive

I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.

Windows Form Application : Publish issue

I'm very new to Visual Studio 2010. I decided to create a simple WFA with C#.
Everything work fine with Images and Audio playback. My intention is to create a standalone application and send it to my friend as a gift. Problem I facing now is that when I tried to publish the application, the Images / Audio is still using the same location in my PC. So it won't play nor display any images.
Any comment on this or guide for me? I did try search for solution but doesn't seems to have any luck.
This is the code that I used to play Audio :
SoundPlayer ply = new SoundPlayer(#"C:\Users\Liam619\Documents\Visual Studio 2010\Projects\BirthdayApp\BirthdayApp\Resources\BirthdaySong.wav");
If I remove or change the path, the Application will hit error for locating the Audio file.
There may be several solutions to your problem.
a) embed the sound into a resource. As a beginner, resources may be a bit tricky to get it right the first time. But I want to encourage you reading something about it. You'll need resources when you want to translate your first program.
b) create an installer which copies the sound file to the installation directory. Try InnoSetup. If you're a programmer, sooner or later, you'll need to create a Setup anyway. Always worth knowing how to do that.
In that case, you still need the path to the sound file, but if you install your EXE into the same path as the sound file, see getting the application's executable directory.
everything in the database whether images or audio refers to your own server database.you have to send the database too with the app and the correct version .NET framework needs to be installed on the target PC.

How to merge 2 zip files together into 1 zip

I am trying to make a custom launcher for Minecraft in C# but I have come across a bump.
I want to add something into it, Minecraft Forge, but the only way I could think of is to change the extension of minecraft.jar to minecraft.zip, extract the contents of the Minecraft Forge.zip and the minecraft.zip into the same folder and then zip that entire folder up into minecraft.jar.
However minecraft.jar has a file named aux.class so whenever my extract script (Made in java) tries to extract it, it simply says:
Unable to find file G:\Programming\C#\Console\Forge Installer\Forge Installer\bin\Debug\Merge\aux.class.
The only other way I can think of is to merge minecraft_forge.zip into minecraft.zip, I have spent around 2 hours looking on Google (watch as someone sees it within a couple of minutes) but it always shows me results for "How to zip multiple files", "How to make a zip file in C#" etc.
So I have come here looking for my answer, sorry if this is a lot to read but I always see comments on here saying "You didn't give enough information for us to help you with".
EDIT: The question in case it wasn't clear is: How am I able to put the contents of minecraft_forge.zip into minecraft.zip?
In your case, if you cannot unzip the files due to OS limitations, you need to "skip" unzipping temporary files to zip them. Instead, only handle input & output streams, as suggested in the answers found here: How can I add entries to an existing zip file in Java?
As you pointed out, "aux" is a protected keyword within windows and it does not matter what the file suffix may be; windows won't let you use it. Here are a couple of threads that discusses this in general.
Ref 1: Windows reserved words.
Ref 2: Windows reserved words.
If you are typing in commands to perform the copy or unzip, there is a chance you can get this to work by using a path prefix of the following \\.\ or \\?\. When I tested this, it worked with either a single or double back-slash following the period or question mark. Such that the following work:
\\.\c:\paths\etc
\\.\\c:\paths\etc
\\?\c:\path\etc
\\?\\c:\path\etc
I used the following command to test this. When trying to rename through windows explorer it gave a "The specified device name is invalid." error message. From the command line it worked just fine. I should point out, that once you create these files, you will have to manually delete them using the same technique. Windows Explorer reports that these text files which have a size of 0 bytes "is too large for the destination file system", ie... the recycle bin.
rename "\.\c:\temp\New Text Document.txt" aux.txt
del "\.\c:\temp\aux.txt"
As far as copying directly from zip or jar files, I tried this myself and it appeared to work. I used 7-zip and opened the jars directly using the "open archive..." windows explorer context menu. I then dragged-and-dropped the contents from forge.jar to the minecraft jar file. Since it is the minecraft jar file with the offending file name the chance of needing to create a temporary file on the filesystem is reduced. I did see someone mention that 7-zip may extract to a temporary file when copying between jars and zips.
7-zip reference on copying between archives
I should point out that my copy of minecraft jar (minecraft_server.1.8.7.jar) did not contain a file named aux.class. I also did not try to use the jar after the copy/merge. Nor did I spend too much time trying to figure out how well it merged the two contents since it appears like there may be a conflict with com\google\common\base\ since there are similar class name but with different $ variable suffixes on them.
I hope these two possible suggestions could give you some room to work with to find a solution for your needs... if you're still looking.

Categories