Compiling in GIFs etc.

D

Daisy

Currently I'm using Image.FromFile() to load files at run-time, but I don't
want to include editable gifs and such in a release. I've checked the
manual, but all I can find under "resource files" and such are xml and text.
Is there anyway I can bundle all of my external files (gifs, wavs, etc.)
into a single file, that can't so easily be messed with by an "experienced"
user ;)
 
C

Chris Hornberger

Add them to your project, set their "build action" to "Embedded
Resource". You can use them via streams against the
"GetManifestResourceStream()". This code-snipped from one of my apps
should get you started.

adbi is the name of my assembly
trans_file.txt is the name of the file I embedded as a resource

the entire spec together adbi.trans_file.txt (assembly.resource_name)
is how you identify a unique resource in an assembly.

try{
Assembly thisAsm = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.StreamReader input = new System.IO.StreamReader(
thisAsm.GetManifestResourceStream( "adbi.trans_file.txt" ) );
this.lblTransactFile.Text = input.ReadToEnd();
input.Close();
} catch(Exception ex) {}
 
D

Daisy

Chris Hornberger said:
Add them to your project, set their "build action" to "Embedded
Resource". You can use them via streams against the
"GetManifestResourceStream()". This code-snipped from one of my apps
should get you started.
<snip>

Thanks, but I'm not using Visual Studio... I'm, er, using a text editor!!
(even for my forms!)...
As well as not really liking it, I'm not paying the price for small hobby
projects..

I don't supposed you know how to include them from a command line?
 
D

Daisy

Jay B. Harlow said:
PMFJI, I realize this is not what you asked.

Have you tried Sharp Develop?
<snip>

Yep!
I wasn't too fond of the code it generated with forms, so I decided to try
doing it myself, and it's dead easy, so I've stuck with it since :blush:)
The C# compile options are listed at:
http://msdn.microsoft.com/library/d...csharpcompileroptionslistedalphabetically.asp

Possible the linkresource or resource option is what you want?

Cheers, but I'd already looked at them, but the docs seemed to suggest
they'd only do xml & txt files
:blush:(
 
J

Jay B. Harlow [MVP - Outlook]

Daisy,
Yep!
I wasn't too fond of the code it generated with forms, so I decided to try
doing it myself, and it's dead easy, so I've stuck with it since :blush:)

You can use Sharp Develop to edit your source and manage your projects
without using their forms designer!
Cheers, but I'd already looked at them, but the docs seemed to suggest
they'd only do xml & txt files
:blush:(
Did you look at the page, or did you try to use them to embed a gif?

The '/resource' option states "To set this option in VS.NET ... set build
action to Embedded Resource".

Well if I can add a GIF to my VS.NET project, set the build action to
Embedded Resource, and it gets included in the executable, that would
suggest to me that on would be able to use /resource:your.gif on csc, and
the gif would be embedded.

If you really would like me to take the time to try it for you, rather than
you just trying it yourself. I will. :-|

Hope this helps
Jay
 
D

Daisy

Jay B. Harlow said:
You can use Sharp Develop to edit your source and manage your projects
without using their forms designer!

hehe, so I can... :p
I'm used to UltraEdit from my ASP coding, so I was just a bit biased, and
I've gotten used to writing C# in it now... I found some weird bugs in C#,
my scrollwheel used to scroll panes around the code window, and never the
code window, regardless of where focus was... kinda got annoyed and binned
it off ;)

Did you look at the page, or did you try to use them to embed a gif?

The '/resource' option states "To set this option in VS.NET ... set build
action to Embedded Resource".

I wanted to include files in a seperate file, not the exe, so I followed a
link about resource files generated with resgen.exe, where I read "The
Resource File Generator converts .txt files and .resx (XML-based resource
format) files to common language runtime binary". That's why I decided to
post here assuming it was dead easy and someone would post a few lines of
code :)

Well if I can add a GIF to my VS.NET project, set the build action to
Embedded Resource, and it gets included in the executable, that would
suggest to me that on would be able to use /resource:your.gif on csc, and
the gif would be embedded.

If you really would like me to take the time to try it for you, rather than
you just trying it yourself. I will. :-|

It's not that I'm too lazy to try it, but the way you've shown would embed
in the exe? and the other way I've read only seems to do txt & xml :-\
 
J

Jay B. Harlow [MVP - Outlook]

Daisy,
Going back to your original question: ;-)
Is there anyway I can bundle all of my external files (gifs, wavs, etc.)
into a single file, that can't so easily be messed with by an "experienced"
user ;)
.... long discussion snipped ...
It's not that I'm too lazy to try it, but the way you've shown would embed
in the exe? and the other way I've read only seems to do txt & xml :-\
--
What kind of 'external file' would you like it included in?

1. You can include them in the exe itself, which was what I thought you
wanted.
2. You can include them in one of your DLL, which is about the same as
above.
3. You can include them in a .resource file, which can have locking issues
4. You can include them in a resource/satellite DLL, unlike #2 this dll does
not contain code.
5. You can include them in a .resx file, which you can either use, or create
a .resource file from.
6. You can include them in a .zip file, password protected to avoid 'easily
be messed with'.
7. ...

Generally I include my 'resources (gifs, wavs)' as embedded resources in my
executable.

The txt & resx file are input into a .resource file, the .resource file can
be input into a DLL or EXE. You can also directly embed the gif into the
exe.

For further details see:
http://msdn.microsoft.com/library/d...localization_using_the__net_framework_sdk.asp

Hope this helps
Jay
 
D

Daisy

Jay B. Harlow said:
Going back to your original question: ;-)
;-P

What kind of 'external file' would you like it included in?
<snip>

I didn't want to bloat the exe with lots of toolbar buttons etc. but also
didn't really want the user to think they knew what they were doing and
"customise" my app ;o)
Any external file would do, I didn't think about putting them into a dll,
that might do the job :blush:)
If not, I'll just have to go bloaty and stick them in the exe... This does
have the side-effect of being able to run from a single file :))

I'll have a look through the link you posted when I get back from work too.
Thanks Jay :blush:)
 
C

Chris Hornberger

Oh, no problem. Have your resources (icons, bitmaps, etc) in their
respective file formats and simply add them on the command-line with
the /resource: parameter.

Complete info is available by running the compiler with the /?
parameter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top