Delphi: Organize RCData into hierarchy way - delphi

The following print screen shows list of resources file embedded into the package. Is it possible to organize the highlighted resources (SE_BUG...SY_VIEW) into hierarchy way ? What i mean here is that can I create a folder call Metadata under the folder RCData and move all the highlighted resources (SE_BUG...SY_VIEW) into the Metadata folder ? In other words, I want to achieve the highlighted resources in well organized such as the way of MainIcon folder.

the RCData is a type of resource not a folder. so you must use another type of resource to see the data in another folder.
This is the list of the types of resources available in delphi wich is based in the Windows Resources types.
const
RT_CURSOR = MakeIntResource(1);
RT_BITMAP = MakeIntResource(2);
RT_ICON = MakeIntResource(3);
RT_MENU = MakeIntResource(4);
RT_DIALOG = MakeIntResource(5);
RT_STRING = MakeIntResource(6);
RT_FONTDIR = MakeIntResource(7);
RT_FONT = MakeIntResource(8);
RT_ACCELERATOR = MakeIntResource(9);
RT_RCDATA = Types.RT_RCDATA; //MakeIntResource(10);
RT_MESSAGETABLE = MakeIntResource(11);
DIFFERENCE = 11;
RT_GROUP_CURSOR = MakeIntResource(DWORD(RT_CURSOR + DIFFERENCE));
RT_GROUP_ICON = MakeIntResource(DWORD(RT_ICON + DIFFERENCE));
RT_VERSION = MakeIntResource(16);
RT_DLGINCLUDE = MakeIntResource(17);
RT_PLUGPLAY = MakeIntResource(19);
RT_VXD = MakeIntResource(20);
RT_ANICURSOR = MakeIntResource(21);
RT_ANIICON = MakeIntResource(22);
the MAINICON folder in your sample image is a RT_GROUP_ICON, wich represent a group of icons with different sizes and colors, because that they appear like a folder.

Resource files don't have a structure. All you have is a bunch of resources that are identified by two parameters: Name and resource type.The icon resource you see is of type "ICON" and is named "MAINICON" and is just an icon file. And icon files allow multiple images to be part of a single resource file. So what you're seeing is not the structure of the resource but the structure of the icon file as a special resource. The resource explorer is just capable of detecting these special resource files and thus displays them in this special way.So basically, you have a main icon which only contains an icon of 32x32 pixels x32-bits colors. If you'd used an icon file that contains multiple images, you would have seen more in that list.

The Resource Explorer demo comes with source code, so yes, you can. :-)

Related

How to access a list of all files in resource folder of my project?

I have some .TXT files saved in Resource folder of my project. I want to display a list to user in which all files from resource folder are shown and user can select the file he desires.
Later on i will read the user selected file and show it on screen.
Take a look at the NSBundle function pathsForResourcesOfType:inDirectory: That will give you a list of the paths to all the files in a sub-bundle of a bundle. if you call that method on the main bundle you'll get a list of all the files of a certain type in a sub-directory of the main bundle.
(I have no idea how to make use of these functions from xamarin.)
This gets FileInfo's on all txt files in the resources:
var fileInfos = NSBundle.GetPathsForResources(".txt", path)
.Select(a => new FileInfo(a));
Now you have the short name, full name etc to play with:
foreach (var fileInfo in fileInfos)
{
System.Diagnostics.Debug.WriteLine(fileInfo.Name);
using (var streamReader = new StreamReader(new FileStream(fileInfo.FullName, FileMode.Open)))
{
System.Diagnostics.Debug.WriteLine(streamReader.ReadToEnd());
}
}

read file from res folder blackberry

I want to read file from "res" folder on blackberry. The file that i used is a file javascript.
I used this code InputStream in = classs.getResourceAsStream("file.js");. But i get "could not find this path" and I use also
String srcFile = "/res/ressourcesWeb/file.js";
FileConnection srcConn = (FileConnection) Connector.open(srcFile, Connector.READ);
InputStream in = srcConn.openInputStream();
but i got an exception.
Can any one help me to read the file and give me the right path that should I use?
Your res folder has to be inside src folder to be accessed from your code.
src folder is the root folder of your project package. And all folders outside of src folder are invisible for the code at runtime.
Check this post for more details: Blackberry runtime error: FRIDG: could not find img/logo.png
There's file location principle described.
You actually do not need to put your resources under the src folder for them to be accessible from your code.
That is one way to do it, but I don't think it's the best way. Files under the src folder should really be source code, not images, or other resources. For JavaScript resources, it's debatable whether those should be under src or not. Most projects I've seen have used the src folder for only Java source code.
In any case, if you would like to keep your file (or other resources, like images) outside the src folder, you can do so. The BlackBerry plugin for Eclipse actually sets it up like this by default, when you create a new project. There is a res folder at the top level, next to (not under) src.
If you have
src\
src\com\mycompany\myapp\
res\
res\resourcesWeb\
res\resourcesWeb\file.js
Then, you can open the file like this:
String jsPath = "/resourcesWeb/file.js";
InputStream input = getClass().getResourceAsStream(jsPath);
byte [] content = IOUtilities.streamToBytes(input);
String contentAsString = new String(content);
P.S. You also can probably do this:
String jsPath = "/file.js";
InputStream input = getClass().getResourceAsStream(jsPath);
and not specify the path to the resource. Obviously, this will only work if there are no naming conflicts in your resource folders (e.g. you don't have /res/resourcesWeb/file.js and also /res/otherPath/file.js)

Blackberry res folder naming convention

I created a static function like this.
public static Bitmap Bitmap(String path) {
Bitmap bitmap = Bitmap
.getBitmapResource(Display.getWidth() + "/" + path);
System.out.println(Display.getWidth() + "" + path);
return bitmap;
}
However, when I called like this,
private Bitmap download = Config_GlobalFunction.Bitmap("btn_download.png");
The output gave me FRIDG could not find 320/btn_download.png.
In my res folder, I got an folder which was img and inside img got 6 different folders which were 160, 240, 320, 360, 480 and 640 folder.
How can I call correct folder's image based on Display.getWidth()?
It is possible to have a folder hierarchy under the /res folder but you must use getClass().getResourceAsStream(path) rather than Bitmap.getBitmapResource() in order to create your resource.
This example creates a Bitmap from the path /res/img/hi_res/ui/action_arrow.png:
String imagePath = "/img/hi_res/ui/action_arrow.png";
InputStream is = getClass().getResourceAsStream(imagePath);
byte[] imageBytes = IOUtilities.streamToBytes(is);
Bitmap b = Bitmap.createBitmapFromBytes(imageBytes, 0, imageBytes.length, 1);
It's a bit more work but it does mean you can have a nice folder structure, rather than hundreds of images lumped together in a single folder.
I've had problems with this before. BlackBerry apps don't seem to be well setup to handle resource files in subfolders. That is, you can store your resources in folders, but when bundled into your app (.cod file), they will essentially all be dumped into the same folder.
As you can see, that causes problems if you have multiple resources with the same name (but in different folders).
I used to use the Netbeans IDE to build BlackBerry apps, and with the Netbeans BlackBerry plugin, it seemed to handle this. But, with the RIM JDE, or Eclipse plugin, it doesn't. Perhaps it's something in the ant build script behind the toolset?
Anyway, I know you would like to do something similar to Android, where you would have:
res/drawable-hdpi/icon.png
res/drawable-mdpi/icon.png
res/drawable-xhdpi/icon.png
and pick the correct version of icon.png based on screen size / resolution. That's a good idea.
However, for simplicity, I would probably recommend changing your system to just use prefixes on your resource names, instead of folders. It's a pain, I know, but BlackBerry seems to handle it better.
So, just call your images:
res/img/320_btn_download.png
res/img/360_btn_download.png
res/img/480_btn_download.png
and then your code can be:
public static Bitmap Bitmap(String path) {
return Bitmap.getBitmapResource(Display.getWidth() + "_" + path);
}
if u want to get images depending on their resolutions then...give names to the images according to its resolution like 320x240_img1, 360x480_img1. no need to place these images in different folders....dump these images in ur res folder and call like this
int x = Display.getWidth();
int y = Display.getHeight();
String xx = Integer.toString(x);
String yy =Integer.toString(y);
_encImg = EncodedImage.getEncodedImageResource(xx+"x"+yy+".jpg");

Programmatically Add Files To TFS with dependency files

How can I programmatically add files to a TFS project that have code behind files. I can say the following to add files. That will only add single files to a project and not the file plus the code behind file. I'm trying to add a resource file and it's code behind that were dynamically generated to a TFS project.
workspace.PendAdd(filesWithPathToEdit, true);
I had to put it in a T4 template to get access to the current Visual Studio DTE otherwise it would randomly work if I tried it outside of a t4. You can use the DTE to get a list of projects from a solution then add a ProjectItem and it contains ProjectItems so you can add your code behind there. ResxContainer is a custom class to just contain all information about my resx file i needed.
EnvDTE.DTE dte = (EnvDTE.DTE)HostServiceProvider.GetService(typeof(EnvDTE.DTE));
//dte = (EnvDTE.DTE) hostServiceProvider.GetService(typeof(EnvDTE.DTE));
//dte = (EnvDTE80.DTE2)Marshal.GetActiveObject("VisualStudio.DTE");
Projects projects = dte.Solution.Projects;
if (projects.Count > 0)
{
IEnumerator enumer = ((IEnumerable)projects).GetEnumerator();
while (enumer.MoveNext())
{
Project proj = (Project)enumer.Current;
if (proj.Name == projectName)
{
foreach (ResxContainer res in items)
{
ProjectItem item = proj.ProjectItems.AddFromFile(res.ResxPath);
item.ProjectItems.AddFromFile(res.CodeBehindPath);
}
}
}
There's no way for it to automatically know if a file depends on another. However, you can decide on your own which files will typically have a code behind file associated with them and add them yourself.
For example:
If you begin to add a file with an .aspx extension, then those files, as we know, typically have a code behind file. That code behind file, we can assume, has the same file name, with .cs appended. So, if we have "Default.aspx", then we can safely assume that there will be a "Default.aspx.cs" and that they are dependent on each other, so we should add both.
The same thing goes with .xaml and .xaml.cs files.

how to embed an xml file to a resource file

i want to embed a xml file to a resource file in my project,whenever i need the file i must get it from resource and use it,how to do this and i want to modify the contents of the xml file depending upon my requirements.how to do this
If you add the XML file to a Visual Studio project and, in the Property window for it, select Build Action: Embedded resource, the file will be embedded into the build output artifact for that project.
To access it from code, use something like:
string resourceName = "Namespace.Prefix.FileName.xml";
Assembly someAssembly = LoadYourAssemblyContainingTheResource();
XmlDocument xml = new XmlDocument();
using (Stream resourceStream = someAssembly.GetManifestResourceStream(resourceName))
{
xml.Load(resourceStream);
}
// The embedded XML resource is now available in: xml
If the resource you're loading is embedded in your own assembly, you can do something like Assembly.GetExecutingAssembly() to achieve what I listed as LoadYourAssemblyContainingTheResource() above, or possibly typeof(SomeTypeInYourResourceAssembly).Assembly
It's unclear what you mean by "want to modify the contents" - you cannot modify the resource inside the assembly at run-time, but whenever you change the XML file and recompile, the new version will be embedded.

Resources