How to include resource files in Theos makefile? - makefile

I made a fully functional tweak with theos and I need to use an image file
in it , the code for getting the image is correct (tested on Xcode) .
but the image isn't included in the final DEB file .
and I have this makefile :
SDKVERSION=6.0
include theos/makefiles/common.mk
include theos/makefiles/tweak.mk
TWEAK_NAME = MyTweak
MyTweak_FRAMEWORKS = Foundation CoreGraphics UIKit
MyTweak_FILES = Tweak.xm image.png
include $(THEOS_MAKE_PATH)/tweak.mk
But when I try to compile I get :
No rule to make target `obj/image.png.o', needed by `obj/MyTweak.dylib'. Stop.
what can I do to include it ??
(Sorry for bad syntax , asking from iphone).

MyTweak_FILES variable should only include files that can be compiled. Make file handles resources differently.
To include resources you need to create a bundle as follows.
1) Create a folder called Resources in the tweak.xm directory.
2) Put all your resource files (all your PNG's) into that folder.
3) Add the following info to your make file
BUNDLE_NAME = your_bundle_identifier
your_bundle_identifier_INSTALL_PATH = /Library/MobileSubstrate/DynamicLibraries
include $(THEOS)/makefiles/bundle.mk
4) Define your bundle as follows on top of your tweak.xm file.
#define kBundlePath #"/Library/MobileSubstrate/DynamicLibraries/your_bundle_identifier.bundle"
5) You can now initialize the bundle and use the images within your tweak as follows:
NSBundle *bundle = [[[NSBundle alloc] initWithPath:kBundlePath] autorelease];
NSString *imagePath = [bundle pathForResource:#"your_image_name" ofType:#"png"];
UIImage *myImage = [UIImage imageWithContentsOfFile:imagePath]
In the above steps replace your_bundle_identifier with your tweaks bundle identifier which would be in the control file. (ex: com.yourdomain.tweak_name)
Also replace your_image_name with the name of the image you want to use.
You can pretty much use any resources (ex: sound files) the above way.

In addition to the posted answer, it's common practice to place bundles in "/Library/Application Support/" rather than "/Library/MobileSubstrate/DynamicLibraries/"

Related

Set environment variable for babel ios bundle build per scheme in React Native

I want to set a certain environment variable per scheme to be available inside babel.config.js so that I can turn a certain plugin on or off. How can I achieve this? I already tried setting the variable inside the PBXShellScriptBuildPhase phase but it applies to all schemes.
You can create a user defined setting in Build Settings tab, for each scheme, and then include that as a key inside Info.plist file. Then create header and implementation file to export this variable to react native side. Like so,
// RNConfig.h
#import <React/RCTBridgeModule.h>
#interface RNConfig : NSObject <RCTBridgeModule>
#end
// RNConfig.m
#import "RNConfig.h"
#implementation RNConfig
RCT_EXPORT_MODULE();
- (NSDictionary *)constantsToExport
{
NSString* custom_val = [[[NSBundle mainBundle] infoDictionary] valueForKey:#"YOUR_CUSTOM_VALUE"];
return #{#"custom": buildEnvironment };
}
#end
Then you can just import the config from Native modules as
const { RNConfig } = NativeModules;
and use the variable inside the babel config file

Compass sprite path causing error

I've tried many responses already, but for some reason I can't get this to work. The error is:
No files were found in the load path matching "sprites/*.png"
My config.rb code:
relative_assets = true
cache=false
Encoding.default_external = "utf-8"
#########
# 1. Set this to the root of your project when deployed:
http_path = "/"
http_generated_images_path = "../images";
# 2. probably don't need to touch these
css_dir = "../css"
sass_dir = "./"
images_dir = "../images"
images_path = "../images"
javascripts_dir = "../js"
environment = :development
line_comments = true
My folder structure:
css
images
- sprites
scss (config.rb located in scss folder)
- partials
- - _mixins.scss (the file where the error is occuring)
And in mixins:
#import "sprites/*.png";
Any ideas what's wrong with the paths?
Thanks for any help.
First question is: do you actually have any files in your sprites folder? If yes, try adding this setting:
generated_images_path = "../images"
http_generated_images_path will be used to define what is the final path for the generated image, in the final (compiled) css, so maybe the setting above (without http_) is the one you need. My project structure is different but it works fine for me, I have more settings pointing to the same path though, this is what I have:
images_dir = "/assets/img"
generated_images_path = "assets/img"
http_images_dir = "assets/img"
http_images_path = "assets/img"
If just the first one doesn't solve the problem for you, try maybe adding all these?
Worst case change your project structure so you don't have to go up one level to get the folder (not saying that this is the problem as it shouldn't be but well, testing is the best way to find out)
I tried various options here. In the end I updated to Ruby 2.1.5 and turned off the Compass "save on build" plugin for Sublime, which seems to have fixed it. Not a perfect solution, but it works for now!

Use relative path in Firefox extension

I develop Firefox extension with bundled executable file which should be run on browser startup.
To run process I need get nsIFile or nsILocalFile instance which points to executable file.
I know one solution how to get it using directory service:
var file = Components.classes["#mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
file.append("extensions");
file.append("<extension id>");
file.append("<relative path>");
But this solution has two disadvantages:
It doesn't work in development mode, when instead of installed extension I have only text file with real extension path
I'm not sure that it will work on all Firefox configurations because of hardcoded "extensions" part of the path
So is there any nicer way to run executable file which comes with Firefox extension?
Thanks.
You are making way too many assumptions about the directory structure of the Firefox profile - don't. The Add-on Manager API lets you get the path of a file inside the extension, you should use it:
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("<extension id>", function(addon)
{
var uri = addon.getResourceURI("<relative path>");
var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file;
...
});
A restartless addon's startup function (in the bootstrap.js file) will receive, as its first parameter, the path where the addon is installed. You can then play various tricks to read files inside the .jar file, if any: see https://github.com/protz/GMail-Conversation-View/blob/master/bootstrap.js#L55 as an example.
In a non-restartless case, I must confess I don't have much of an idea :).
I found this thread looking for a way to reference a path to an image hosted in extension's directory from a content script. Here's a solution:
Include your files in web_accessible_resources in the extension's manifest.
"web_accessible_resources": [
"images/*"
]
Absolute paths to these resources contain randomly generated UUID, therefore we're using runtime.getUrl() giving it the path relative to manifest.json. Example:
let myImg = document.createElement('img');
myImg.src = browser.runtime.getURL("images/my-img.png")

Info.plist file missing/Unable to set & retrieve CFBundleVersion from my Cocoa project

I created a new cocoa project using the command-line tool template. I need to be able to set/retrieve the version from the bundle, but the infoDictionary in my mainBundle is only showing three basic items when I do po [[NSBundle mainBundle] infoDictionary]:
{
CFBundleExecutablePath = "...";
NSBundleInitialPath = "...";
NSBundleResolvePath = "...";
}
I do have a Common-Info.plist file, but changing values in here doesn't seem to affect anything. I've also tried to add an Info.plist to my project, but it's ignored.
Is there something special I need to do to get it using the right file?
This is Xcode 3.2.6
EDIT FOR FIX
The key was to add this to my 'Other linker flags' option in the target/get info:
-sectcreate __TEXT __info_plist Info.plist
You can embed the Info.plist file in a special section of your binary. Daniel Jalkut's blog has some good information on it. Check out the "Embedding Info.plist" section here: http://www.red-sweater.com/blog/2083/the-power-of-plist

Get Bundle name from its executable

Given the path for a bundle, how can I get the name of its executable?
Example:
blahblah.app
should give me
blahblah.app/Contents/MacOS/blahblah
Vice versa will also be okay
NSString *exe = [[NSBundle bundleWithPath:thePath] executablePath];
You can also use the URL variants if you're on Snow Leopard and want URLs instead.

Resources