Editing plist from c++ code - c++

So I have a code written in c++. I am trying to get a user's preference through an application. Depending on the sent value, I need to update a key in the plist. I can't find any way to do so in C++. Any suggestions?

You can edit a plist by executing plistbuddy command using system() call. An example to add a key value pair to plist file using system() is given below.
system("/usr/libexec/PlistBuddy -c \"Add :ASSET_ID string '1'\" \"/Library/Application Support/MyApp/ABC.plist\"");
Given below is the plistbuddy command given to system call.
/usr/libexec/PlistBuddy -c "Add :ASSET_ID string '1'" "/Library/Application Support/MyApp/ABC.plist"
More details on plistbuddy here - https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/PlistBuddy.8.html

I am guessing a few things here, because from your questions it is not quite clear the setup you are working with. I'm assuming you have a cocoa app with part of the code written in c++ (maybe based on some third party GUI library, e.g. FLTK, that hides the obj-C part?).
Anyway, in my opinion the best and safest way to go about this kind of things is to write small c++ wrappers for objective-c/cocoa code in a .mm file. You can then use the proper cocoa facilities to robustly locate and manipulate the plist (your probably want to look inside NSBundle and NSPropertyListSerialization in your case).

Related

.How do you create a new file in Ocaml and where does it store it?

I can't seem to find the answer, how do you create a new file in Ocaml? Do you edit your file in the terminal? Where does the source code appear?
I think you're asking how to write code in OCaml, i.e., how to create an OCaml source file. (This isn't completely clear. You could be asking how to write OCaml code that creates a file.)
The details of creating OCaml source depend on your development environment, not on the language itself. So there is no one answer.
The general answer is that you can use any tool you like that knows how to create a text file. If you like working from the command line (as I do) you can work in a terminal environment and run some kind of vintage text editor from the last millennium (as I do). If you like a GUI environment, you can run some kind of "programmer's editor" from the current millennium, or really any kind of editor that creates basic utf-8 files (or even ASCII files).
Generally the editor will have to be told where to store the files that you edit. You would probably want to make some kind of folder for the project and make sure you store the text files in there.
I hope this helps! If you have any programmers nearby, they can probably get you started a lot faster than asking on StackOverflow.

c++ what is the *clever* way of creating setup program and handle extraction

I know how to create and code my own setup program but i need to be redirected at some point. This point i'm sure inlight other people too.
I created a setup project. All is done. Except, installation files inside of EXE.
I know 2 different ways of doing this:
Create resource in EXE and embed RAR/ZIP file.
Put compressed archive with files along with EXE. EXE will read contents and data from this protected and compressed ZIP.
But what i want is number 1. I want to embed it. But;
What is the proper way of embedding this? Are other setup creators do the same thing? Embed resource as compressed single zip in EXE? Or do they another trick?
How do you extract files? On the fly by memory? Like read each file one-by-one. Synced. Or first, copy ZIP to temp and extract from it.
Or even embed all files separately to the resources.
I, even think that if i should create simple MSI without dialogs and embed it and run from background but i want to take all control. I want everything belongs to the original setup that i created.
Note:
I want to make my own dialogs, effects, procedures, functions and
steps. Yes, MSI is acceptable but i will stick with its features. Oh,
If im able to extend it, why should i spent more time doing this
instead of making my own? I am so confused... I am talking about very big setup project here. Not just a standard ugly UI with less features. At least, im gonna try :)
Do not give me any sample/code just show me a correct path, please.
Best options here:
Create ZIP compatible EXE that reads itself as ZIP and read the file list and extract.
Create non-zip compatible EXE that has a hidden body somewhere and read that area (seek) and get the list & extract.
The proper way to do it is to use the Windows installer technology, aka MSI. There is a nice, Microsoft blessed toolset called WiX that you can use to greatly simplify the process.
http://wix.codeplex.com/
If you are truly intent on reinventing the wheel, you can look through the source code to WiX on how things are done.
Best options here:
Create ZIP compatible EXE that reads itself as ZIP and read the file list and extract.
Create non-zip compatible EXE that has a hidden body somewhere and read that area (seek) and get the list & extract.
Why write your own? Much easier to use WiX (http://wixtoolset.org/) with optionally a graphical interface like WiXEdit (http://wixedit.sourceforge.net/). Have you thought about additional requirements like uninstall etc...
Good luck!
Would InnoSetup help with your problem? You can personalise the dialogs and extend its functionality quite a lot.

How to make a GUI out of a already done code in C++

I want to make a GUI . I have a code that runs, made in C++. The project is made in Visual Studio(Visual C++ 2010 Express).
The outputs now are printed in command line. I want to tranform this to be printed to a window.
Is there a way to do this in this already made project ? Or I have to make a new one.
P.S. The code is consists of many, about 20 .cpp files and about 5 .h headers.
Following my comment on your original post here's some more information that will help you get through this:
Simply turn your "cout << ...." calls (or printf if the code is
actually C) to append the text to the UI control you want the output
to be displayed in? Or you can check this "hack" out:
cplusplus.com/forum/general/27876
Now simply add a new source file to the project: call it.. MyProjectGUI.cpp
Follow this guide here to setup the window on your project:
http://msdn.microsoft.com/en-us/library/bb384843.aspx
Then go through the rest of your code (or use the hack mentioned above or some kind of pipe to redirect your output (probably a lot! more complicated than the following method) and simply replace your cout << / printf calls with something like what's detailed in here: http://www.programmersheaven.com/mb/windows/105327/105327/appending-text-to-edit-control/
You'll find the basic idea of your modifications to be along these lines:
Create a simple window
Add a new edit field to the window (http://en.wikibooks.org/wiki/Windows_Programming/User_Interface_Controls and http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx)
Replace all console printing calls with a call to your append function for the edit box in the GUI
Best of luck with this (I might write up some code if I'm bothered but don't count on it -> no time. You should be able to figure it out with what I've posted though)
You dont have to do another project. It is enough to include headers and add libraries to linker. You should try a QT which is portable, well written and easy to learn. My one advice is to stay as portable as possible, in example you can create a makefile for your project so add new libraries will be a quiet easy job and not related to IDE . Dont stick to one environment.

Generating a C++ classes from IDL file using MICO (CORBA)

I wan to generate a C++ classes from a IDL file using MICO in the contxet of CORBA. I download the mico-2.3.13.zip but iI don't know how to use it. Please if someone can help me and thanks all.
The answer would probably be longer that would comfortably fit in a short reply, but here are some pages with helpful starter info.
This class webpage has a mini tutorial using mico
http://www.cs.wichita.edu/~chang/lecture/cs843/program/mico-idl.html
Here's another fairly simple tutorial page
http://people.inf.ethz.ch/roemer/micodoc/node16.html
You first need to compile MICO from the sources. Depending on your operating system and environment this will require different steps. In linux/mac os x they are basically calling the ./configure script and then make if it did not fail. Under windows I think that you can call nmake directly (with some options, read the README files).
After compilation completes (this may take a few minutes) and if everything goes fine, you should have the executables and can use them to create your own CORBA interfaces and services.

C++ Passing Options To Executable

How do you pass options to an executable? Is there an easier way than making the options boolean arguments?
EDIT: The last two answers have suggested using arguments. I know I can code a workable solution like that, but I'd rather have them be options.
EDIT2: Per requests for clarification, I'll use this simple example:
It's fairly easy to handle arguments because they automatically get parsed into an array.
./printfile file.txt 1000
If I want to know what the name of the file the user wants to print, I access it via argv[1].
Now about how this situation:
./printfile file.txt 1000 --nolinebreaks
The user wants to print the file with no line breaks. This is not required for the program to be able to run (as the filename and number of lines to print are), but the user has the option of using if if s/he would like. Now I could do this using:
./printfile file.txt 1000 true
The usage prompt would inform the user that the third argument is used to determine whether to print the file with line breaks or not. However, this seems rather clumsy.
Command-line arguments is the way to go. You may want to consider using Boost.ProgramOptions to simplify this task.
You seem to think that there is some fundamental difference between "options" that start with "--" and "arguments" that don't. The only difference is in how you parse them.
It might be worth your time to look at GNU's getopt()/getopt_long() option parser. It supports passing arguments with options such as --number-of-line-breaks 47.
I use two methods for passing information:
1/ The use of command line arguments, which are made easier to handle with specific libraries such as getargs.
2/ As environment variables, using getenv.
Pax has the right idea here.
If you need more thorough two-way communication, open the process with pipes and send stuff to stdin/listen on stdout.
You can also use Window's PostMessage() function. This is very handy if the executable you want to send the options to is already running. I can post some example code if you are interested in this technique.
The question isn't blazingly clear as to the context and just what you are trying to do - you mean running an executable from within a C++ program? There are several standard C library functions with names like execl(), execv(), execve(), ... that take the options as strings or pointer to an array of strings. There's also system() which takes a string containing whatever you'd be typing at a bash prompt, options and all.
I like the popt library. It is C, but works fine from C++ as well.
It doesn't appear to be cross-platform though. I found that out when I had to hack out my own API-compatible version of it for a Windows port of some Linux software.
You can put options in a .ini file and use the GetPrivateProfileXXX API's to create a class that can read the type of program options you're looking for from the .ini.
You can also create an interactive shell for your app to change certain settings real-time.
EDIT:
From your edits, can't you just parse each option looking for special keywords associated with that option that are "optional"?