Hack Forums
[.NET] [Solved] How to save files as new resource? Like a .Zip file or .exe not Txt files? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [Solved] How to save files as new resource? Like a .Zip file or .exe not Txt files? (/showthread.php?tid=4957187)



[Solved] How to save files as new resource? Like a .Zip file or .exe not Txt files? - Jackie Chun - Aug 20, 2015

SOLUTION: You don't....



I want to know how to actually ADD a resource, not write an existing one. Does anyone have any clue on how to do this, google has yet again failed me.

I'm trying to do this

ZipFile.CreateFromDirectory(NewResource, MyResources)

Maybe I can't use createfromdirectory like that or that might not be how it works, but I want to save to my Resources. I just don't know how to,

DumbedDown: Click button, openfiledialog, choose .exe, it saves to resources for later use.


Also I've tried ResourceWriter and Adding a resource that way but as I stated I want to add actual Files, not just strings / text. Unless somehow I can manage it through memory or somethign idk.


Welp, I'm having a problem using a Boolean in a Loop with my Save to the fkn Folder Method.

Logic why do you fail me?


* - Nikey646 - Aug 20, 2015

If you want to add a new resource to your executable at run time, that is impossible. Resources are stored in resx files, which is a custom XML structure, when images or binary files are added to the resx file, the bytes for the new item are stored in base64. The reason adding a new resource to your executable at run time is impossible, is actually because the resx file with all your resources is compiled into the resultiing binary. You would literally need to re-compile your application every time you want to change a resource.

If that is not what you want to do, ignore this post ;D


* - Jackie Chun - Aug 20, 2015

(Aug 20, 2015 04:49 PM)Nikey646 Wrote:  If you want to add a new resource to your executable at run time, that is impossible. Resources are stored in resx files, which is a custom XML structure, when images or binary files are added to the resx file, the bytes for the new item are stored in base64. The reason adding a new resource to your executable at run time is impossible, is actually because the resx file with all your resources is compiled into the resultiing binary. You would literally need to re-compile your application every time you want to change a resource.

If that is not what you want to do, ignore this post ;D

I want to add a new resource to my executable at run time.

My google adventures brought me across what you're talking about with resx files. There was something about using resXresourcewriter or some weird shit like that but I couldn't store actual files like Images or zip files to it only strings.

How do I make my program recompile it's self with a custom resx file that it adds to? I don't understand how this could be impossible, I mean physically adding files or copying them, into your file to store them shouldn't be "impossible".


* - _B1N4RY_ - Aug 20, 2015

You would have to code your own JIT compiler basically, if I'm not mistaken.
en . wikipedia . org/wiki/Just-in-time_compilation


* - Jackie Chun - Aug 20, 2015

Can someone give me an example please?


* - BahNahNah - Aug 20, 2015

Like this?

Code
using (var writer = new ResourceWriter("mysettings.resources"))
{
    writer.AddResource("Example1", "Hello");
    writer.AddResource("Example2", 11);
    writer.AddResource("Example3", File.ReadAllBytes("Add.exe"));
    writer.Generate();
    writer.Close();
}



* - Jackie Chun - Aug 20, 2015

(Aug 20, 2015 09:23 PM)BahNahNah Wrote:  Like this?

Code
using (var writer = new ResourceWriter("mysettings.resources"))
{
    writer.AddResource("Example1", "Hello");
    writer.AddResource("Example2", 11);
    writer.AddResource("Example3", File.ReadAllBytes("Add.exe"));
    writer.Generate();
    writer.Close();
}

Specifically not. I thought I CLEARLY covered that, guess not.