How to choose and open a file during runtime with C++? - c++

At the moment I am creating an Editor for Textures and I want to choose the textures during runtime. Later I would like to choose the save directory for new textures.
I found the
How to: Open Files Using the OpenFileDialog Component. But I think this is not the solution.

(assuming you are on Windows, pas per screenshot)
If you simply want to select a folder, you can use SHBrowseForFolder.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx
M.

You need to look at the Common Dialog Library.
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms645524(v=vs.85).aspx
Or, if you are only interested in Vista/Windows 7 support, you could consider the Common Item Dialogs instead.
http://msdn.microsoft.com/en-gb/library/windows/desktop/bb776913(v=vs.85).aspx
For 'native' C++ you wouldn't be able to easily use the .NET components that your link refers to.

I have solved my problem with using the dirent.h file. I have acknowledge of this file by founding this post How can I get the list of files in a directory using C or C++?
I have write my own fileexplorer by using dirent.h and SFML.
Sorry if i can't illustrate my problem.
but thanks for the replies (:

Related

How to open an FBX file from my UE4 project's interface

I've created an interface for my UE4 project that has an import button. What I want it to do is to access FBX files in the user's desktop and opens the one the user selects.
I've written a c++ code that searches for FBX files in the desktop and returns their names, if found.
I'm kind of confused/stuck at this moment, and don't know exactly how to continue. My question is:
Shall I open the FBX file using c++ or blueprints?
It would be much appreciated if you could elaborate more on the approach you suggest.
Thank you
What I want it to do is to access FBX files in the user's desktop and opens the one the user selects.
"Opening something" does not actually tell us what you want to do.
Open the file with The default application for the file type?
Load the mesh somewhere into RAM?
Spawn objects in UE4 with the mesh?
Who knows what opening means. Opening the file in maya will be quite different from opening it with a hex editor.
Specify what your programm should do.
Shall I open the FBX file using c++ or blueprints?
Appart from what you can add to what I said above this questions answer will be purely subjective if BP is actually capable of doing what you want. IF you are doing good in c++ I suggest to stick with it for file operations.
Here Epics documentation on asset references, this should fit for people finding this thread and probably for you.
https://docs.unrealengine.com/latest/INT/Programming/Assets/ReferencingAssets/index.html
Just use UStaticMesh instead of the filetype used in the examples.
Here a UE4 wiki example implementation of what you could mean:
https://wiki.unrealengine.com/Dynamic_Load_Object
Shall I open the FBX file using c++ or blueprints? It would be much appreciated if you could elaborate more on the approach you suggest.
Yes, you can use the thirdparty libray to import the FBX, such as assimp
https://github.com/assimp/assimp
In the mean time, instead of use static mesh, you could use precedure mesh instead.

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.

C++: How-to create a simple program for moving folders

I want to make a program that moves certain named folders (and all files contained) from directory A to directory B. It was suggested to code in C++. So I was wondering if anyone knew of a simple way to do this, if they could give me a link, and if anyone know's where it's possible to set the directories as variables that can be loaded from a text file. I'm asking this question, because I want to basically have all my program settings and whatnot from the appdata folder since I move between computers alot, be easily transferable.
settings.txt (This is an example of what I mean.)
fldrget = (Folder Name)
fldrdir = (Path to Folder)
fldrplc = (Folder Destination)
Would creating an xml document be a better idea as far as the txt document goes?
Additional Information: OS: Windows(XP, Vista, 7) and I'd like to make this a GUI, but as I'm not familiar with any C language, I'll settle for basics first if anyone can give me a push in the right direction.
Can you provide a bit more information? Are you wanting to write a console application or a GUI? What platform are you targeting? You could use the Win32 API, Boost, Qt, Wx, or a number of others.
You may want to look into using PowerShell. It is much more friendly for a new comer and built-in to Windows 7 and freely available for Windows XP. Just do a google search for moving a directory using PowerShell to get started

mfc directory picker?

I did see this to modify CFileDialog (http://support.microsoft.com/kb/105497) but it looks like a lot more than I need.
I'm using the CFileDialog to pick files, is there a simple way to use it to just select a directory?
Any other suggestions?
(I also saw this but is for XP only?
http://msdn.microsoft.com/en-us/library/aa163948%28office.10%29.aspx)
(VS 6.0 C++)
You will probably want to use the SHBrowseForFolder API. There are lots of wrapper classes out there that make it easier to use. Like this one.
Dundas Ultimate Toolbox has a folder selection drop-down tree. It is nice because you don't need to open a new window just for selecting a folder.
The class is defined in FolderTree.h and is called CFolderTree.

C++, console Application, reading files from directory

I have a directory and I want to read all the text files in it using C++ and having windows OS also using console application
I don't know the files' names or their number
thanks in advance
Take a look at Boost.Filesystem, especially the basic_directory_iterator.
If you want the C++ and portable way, follow the solution by #Space_C0wb0y and use boost.Filesystem, otherwise, if you want to get your hands dirty with the Windows APIs, you can use the FindFirstFile/FindNextFile/FindClose functions.
You can find here an example related to them.