Possible way to collect data from a dropbox folder through vb.net - vb.net

My game relies on a resource folder Located in C's Program Files called 'resources' using pretty basic code to make up the front end of the game
Public Module getItem
Public Item = Image.FromFile("C:\Program Files\GameName\resources\ItemName.gif")
End Module
to get a picture or video, or text as such I'm pulling the request as such for an update
Dim req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("dropbox link to folder")
Dim res As System.Net.HttpWebResponse = request.GetResponse()
Dim ss As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim version As String = ss.ReadToEnd()
so it knows to update but grabbing the entire contents and redownloading it if there's an update in the folder is where im not understanding how i would want to do this in an simple fashion without exhausting memory.
Im familiar with
webclient.DownloadFile("database", FolderName)
This being a method in which you get a .zip folder, which requires unpacking and locating and replacing files and it just feels inefficient.
But if i only make a few changes is there a way to recognize the change and ONLY download the new images that are needed to that resource file without re-downloading everything (300 MB) or if it need be; to re-download everything (replace i suppose), is there a way to unpack the dropbox folder contents that's online into being a download via just picture into the file? I've given thought to the idea of possibly isolating them to a new folder named 'updated content' that just pulls the new pictures/music/videos out each download. Would that be a viable solution? the idea is to throw the new content in the folder to be read. I can just have the EXE updated and with that comes the new code to pull the new content by X method. Doesn't anyone know of a easier way of possibly doing this, i'd like to stick to Dropbox if at all possible.
Any help or advice is greatly appreciated, Thank you.
Central Notes: 'Dropbox Folder Download'

Related

VB.net: Problems with Application.StartupPath

I want to access the path of the folder that my published application has been run from.
Everything I can find says use Application.StartupPath(), but this doesn't work.
I wrote a simple program to display these, published to a single standalone file and then ran it from the directory C:\Users\jerem\Downloads\split.
This is what i got:
Application.StartupPath = "C:\Users\jerem\AppData\Local\Temp\.net\getlaunchdir\jvi1ji54.zau\"
Application.ExecutablePath = "C:\Users\jerem\AppData\Local\Temp\.net\getlaunchdir\jvi1ji54.zau\getlaunchdir.dll"
It seems that running the .exe file creates a temp folder with a load of files in it that are then run. Fine, but it returns the "wrong" results for StartupPath - i.e. not what I want.
How do I fix this?
Thanks
** image of publish settings added as requested by Caius Jard.
picture of publish settings
I'm not sure how you get your image showing application.startuppath as C:\temp\ - that looks like a debug mode shot and my problem only occurs while running the published program.
I suspect you published it with ClickOnce? If you publish it with Folder, it ought to behave as you expect
And when run:
Possibly might be what you are looking for:
Private uriBuilder As New UriBuilder(Reflection.Assembly.GetExecutingAssembly().CodeBase)
Public FullAssemblyPath As String = Uri.UnescapeDataString(uriBuilder.Path)
Public ExeDirectory As String = IO.Path.GetDirectoryName(FullAssemblyPath)

Overwriting Box.com file from API

Currently I am using VB.net to upload files to BOX API, But having issue overwriting a file. I want to use Version upload But where do I need to add the Path parameter or any other necessary parameters to accomplish this? :
Dim tokenProvider As New TokenProvider(clientID, clientSecret)
boxManager.CreateFile("0", "file_name", (file_Stream))
Thanks

Visual Basic 2010- Retrieving images using code

I am making a card game. I have 53 images for the cards and one for the back of the cards. Is there a way I can use the resource file or is there a way I can reference the folder where the program is being held with it still being relatively portable so I can move the folder and the program will still work perfectly. I thought about using a case statement and using the
My.Resources._8Hearts 'For Example
but that would take up a lot of space that I am sure can be avoided. I know this can be used to grab an image:
card1.image = System.Drawing.Image.FromFile("C:\" & variable_so_I_can_get_multiple_cards & ".png")
And using a 'for' statement to place each card in a different slot on the form
Thank you for the help
PictureBox1.Image = Image.FromFile(picPath) can retrieve an image for you,no need to add to resources in VB,and im sure u have worked with Strings so you can dynamically attach the name of each picture name (and I think also extension,.PNG seems to work best for me).
If you need it to move with the installation folder find out what your application path is using MessageBox.Show(Application.StartupPath) and then place a folder of your pictures in there and when publishing don't forget to include the folder yah? And Inno Setup (http://www.jrsoftware.org/isdl.php) is a good publishing tool...so I hear,never used it before.
If this answer works for you please dont forget to accept it as the right answer

Capture and save a photo in XAML/C# for a Windows store application

I'm trying to take and save a photo using a windows surface device.
I'm using the code below to take a photo and this work but I'd like to automatically create a directory on the device's local drive and save this photo there without any dialog prompts.
So the code I use to capture to photo is as follows:
CameraCaptureUI camera = new CameraCaptureUI();
StorageFile file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (file!=null)
{
using (IRandomAccessStream ras=await file.OpenAsync(FileAccessMode.Read))
{
BitmapImage source = new BitmapImage();
source.SetSource(ras);
imageBuildingPhoto.Source = source; // this is just an image control.
}
}
So after this I'd like to automatically save the photo to a new directory. e.g.
My Pictures\NewDirectory\Photo1.jpg
Anybody got any idea how I can do this?
This is a windows store application written using C#4.5 and XAML.
Thanks in advance
Use the CopyAsync method on the StorageFile object you get back (file). You can specify a directory and file name. If you need to create your own directory structure, you will need to enable access to the appropriate library in the Package Manifest then create it in code. You will then use the StorageFolder class and its CreateFolderAsync method to create folders.
http://aka.ms/30Days has some great resources for learning about scenarios like this. Might be worth checking out.
Your code will need to look to see if that folder exists and create it if it does not. Your app will need to declare the capability to access the user's Photos library in the app manifest, too.
To take a picture, your code is correct. I have a walkthrough in case you want to verify it against some other code: http://blog.jerrynixon.com/2012/10/walkthrough-capturing-photos-in-your.html
To interact with the file system, this can be tricky, but I have a longer write up on that if you want to reference it: http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html
The answer to your question is, yes you can. I have done it in my own apps. Now, it's just a matter of you implementing it in yours. You will find it to be pretty easy.

Unraveling the confusion about Embedded Resources

EDIT: Read answer number 1 from Tim Schmelter and then use this question for examples of how to embed resources and access them at runtime.
The subject of embedded resources comes up a lot, especially with people asking how to access the embedded files at runtime. Things get more confusing because Visual Studio gives you 2 different ways of embedding a resource, and different ways of accessing those resources at runtime. The problem is that depending on which method you used to embed the resource, the method you’re trying to use to access the file at runtime might not work. This post is an attempt to clear up all the confusion that I see out there, but I also have a question that nobody can seem to answer factually: Why is the size of my compiled program TWICE the size of the embedded resource (sometimes)? For example if I embed a 20MB file into my project, why does my program compile to 40MB? I haves asked this question in the past and nobody was able to reproduce my results. I found that the reason they were not able to reproduce was because they were embedding the file in a different way. See here:
Method 1:
Double-click on My Project to open the property pages and go to the Resources Tab. Now click Add Resource > Add Existing File. Browse to the file you want to embed. For this example I’m using an executable. You will now see your file on the Resources Tab:
You will also see that a folder named Resources was created under your project and the embedded file has been placed in this folder:
EDIT: THIS NEXT STEP WAS THE PROBLEM. TURNS OUT THAT WHEN YOU ADD A FILE VIA THE RESOURCES TAB YOU SHOULD NOT SET THE BUILD ACTION TO EMBEDDED RESOURCE. Counter intuitive to say the least!
Now with the file selected, look down at the properties window for the file and change the build action to Embedded Resource: (this step should ONLY be performed when you add a file via method 2).
Now compile your program. You will see that the size of your compiled program is at least double the size of your embedded resource. This does not happen with method 2. See here:
Method 2:
Right-click on your project name and choose Add > Existing Item. Browse to your file, and this time you will notice that while it was indeed placed under your project, there was no Resources folder created:
Now once again select the file and change the Build Action to Embedded Resource and compile. This time the size of the compiled program will be as you expected - about the size of the embedded file and not double the size as with method 1.
Which method you use to embed your file will determine which method you can use to access the file at runtime. For method 1 this is very simple, all you have to do is:
My.Computer.FileSystem.WriteAllBytes(Path, My.Resources.ResourceName, Append)
Where Path is the location and name for the file you want to save on the harddrive, ResourceName is the name of the embedded resource that you see in the project window (minus any extension), and Append is whether or not you want to create a new file or overwrite an existing file. So for example, using test.exe from the above images, I could save that file to the C drive like this:
My.Computer.FileSystem.WriteAllBytes(“C:\test.exe”, My.Resources.test, False)
Couldn’t be easier.
Method 2 however doesn’t appear to give you access to My.Resources so it gets a little more complicated. You have to create a Stream to hold the resource, put the stream into a byte array, then write the bytes out to the file system. The simplest way I have found to do this is like this:
Using s As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Project.ResourceName)
Dim bytes(s.Length) As Byte
s.Read(bytes, 0, bytes.Length)
File.WriteAllBytes(OutputFile, bytes)
End Using
With this method ResourceName must contain the file extension AND project name so using our example from above we can just do:
Using s As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(WindowsApplication1.test.exe)
Dim bytes(s.Length) As Byte
s.Read(bytes, 0, bytes.Length)
File.WriteAllBytes(“C:\test.exe”, bytes)
End Using
Text-based files are a little different:
Dim output As String
Using sr As StreamReader = New StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(WindowsApplication1.test.txt))
output = sr.ReadToEnd()
End Using
Using sw As StreamWriter = New StreamWriter(“C:\test.txt”)
sw.Write(output)
End Using
Having struggled with this in the past I hope this will help someone. And if you think you can explain factually why method 1 of embedding a resource bloats my compiled program to double its size, I would really appreciate it.
I assume that Method 1 is adding the files twice.
http://www.vbdotnetforums.com/vb-net-general-discussion/42670-visual-basic-net-2008-get-resource-file-io-stream.html#post121923
At least that is the conclusion of the thread above.
Quote:
You went to the Resources page of the project properties and added the files there, right? You then went into the Solution Explorer and change the Build Action of the files to Embedded Resource, right? That's why you were doubling the file size: you were adding each file twice.
There are two different ways to add resources: on the Resources page of the project properties and in the Solution Explorer. You do NOT do both. If you want to use GetManifestResourcestream then you do NOT use the Resources page. You add the files to the project in the Solution Explorer manually, then you set the Build Action to Embedded Resource.
In future, do one or the other, not both.
Add a file to the Resources page of the project properties and then access it via My.Resources. This will automatically add the file to the project in the Solution Explorer but the Build Action will be None and it should be left that way.
Add the file to the project in the Solution Explorer by using Add New Item or Add Existing Item. Set the Build Action of the file to Embedded Resource and then access the resource using GetManifestResourceStream.
Just an update for anyone who wants to use this code. The code actually writes one additional byte to the file due to zero-based declaration of the byte array.
To get an exact copy of the original file change the code to:
Using s As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(WindowsApplication1.test.exe)
Dim bytes(s.Length-1) As Byte
s.Read(bytes, 0, bytes.Length)
File.WriteAllBytes(“C:\test.exe”, bytes)
End Using