View Full Version : Global Path Solution
Centauri Soldier
11-01-2008, 02:06 PM
I think I've done it!
I have been wanting to call the AutoPlay folder as well as the folder from where the exe is run.
As you may already know, this can be a bit difficult as you have to change the code depending on whether the program is compiled, not-compiled, compiled to an exe, compiled to the hard drive etc.
All these require different code to call the AP folder and the exe folder. well, not anymore. The variable names can be found in the "Global Actions.afg" file. The variable that stores the path to the folder wherein the exe is run is called, plainly "exefolder".
I have tested this to be used with un-compiled projects and projects compiled to an exe and to a hard drive folder. This code has been tested to work with no command line arguments and with external command line arguments.
My brain is melting right now so I may have missed something, let me know if you find a bug.
Enjoy!
~CS.
Centauri Soldier
11-01-2008, 02:41 PM
My thread of inspiration by the way:
http://www.indigorose.com/forums/showthread.php?t=25295
RizlaUK
11-01-2008, 02:44 PM
i did make a suggestion ages ago for a global variable _EXEFolder to hold the path of the sfx exe, but it never made it to the table!
Centauri Soldier
11-01-2008, 03:14 PM
Ok, I read over my post and noticed i forgot to include an example. No need to post a project but here's the idea.
I have a project that gets compiled as an exe. The folder that contains the exe needs to have a subfolder in it called "Projects" (next to the exe file). I need to be able to read and write from/to this folder (as well as access the AutoPlay folder inside the exe file). Since I need to test the project before it's compiled, I need the code to work before and after I compile the project without having to alter it.
This code causes the variable "exefolder" to store the path to the folder where the exe is REGARDLESS of the status of my project (compiled or uncomplied). This is what makes the code so handy; you never again have to find the AutoPlay folder or the exe folder no matter where your project is or if it is compiled or not. The variables will always take you to the right place before and after compilation. I hope I was a bit clearer this time.
Centauri Soldier
11-12-2008, 04:32 PM
Found a serious bug in the code...here's the revised code
--================================================== =========================
--========================== GLOBAL PATH SECTION ============================
--================================================== =========================
if Table.Count(_CommandLineArgs) == 0 then
_AutoPlay = _SourceFolder.."\\AutoPlay";
_ExeFolder = _SourceFolder;
_Audio = _AutoPlay.."\\Audio";
_Buttons = _AutoPlay.."\\Buttons";
_Docs = _AutoPlay.."\\Docs";
_Flash = _AutoPlay.."\\Flash";
_Fonts = _AutoPlay.."\\Fonts";
_Icons = _AutoPlay.."\\Icons";
_Images = _AutoPlay.."\\Images";
_Plugins = _AutoPlay.."\\Plugins";
_Scripts = _AutoPlay.."\\Scripts";
_TempAPFolder = _AutoPlay.."\\Temp";
_Videos = _AutoPlay.."\\Videos";
elseif Table.Count(_CommandLineArgs) > 0 then
sSourcePath = _CommandLineArgs[Table.Count(_CommandLineArgs)];
iSourcePathFound = String.Find(sSourcePath, "SFXSOURCE:", 1, false);
if iSourcePathFound ~= -1 then
sTempPath = _CommandLineArgs[Table.Count(_CommandLineArgs)];
_SourceFolder = String.Replace(sTempPath, "SFXSOURCE:", "", false);
for x = 1, 2 do
iAPFolderLength = String.Length(_SourceFolder);
iErasePoint = String.ReverseFind(_SourceFolder, "\\", false);
sTempExeFolder = String.Left(_SourceFolder, iAPFolderLength - (iAPFolderLength - iErasePoint) - 1);
end
_ExeFolder = sTempExeFolder;
_AutoPlay = "AutoPlay";
_Audio = _AutoPlay.."\\Audio";
_Buttons = _AutoPlay.."\\Buttons";
_Docs = _AutoPlay.."\\Docs";
_Flash = _AutoPlay.."\\Flash";
_Fonts = _AutoPlay.."\\Fonts";
_Icons = _AutoPlay.."\\Icons";
_Images = _AutoPlay.."\\Images";
_Plugins = _AutoPlay.."\\Plugins";
_Scripts = _AutoPlay.."\\Scripts";
_TempAPFolder = _AutoPlay.."\\Temp";
_Videos = _AutoPlay.."\\Videos";
elseif intSourcePathFound == -1 then
_ExeFolder = _SourceFolder;
_AutoPlay = _SourceFolder.."\\AutoPlay";
_Audio = _AutoPlay.."\\Audio";
_Buttons = _AutoPlay.."\\Buttons";
_Docs = _AutoPlay.."\\Docs";
_Flash = _AutoPlay.."\\Flash";
_Fonts = _AutoPlay.."\\Fonts";
_Icons = _AutoPlay.."\\Icons";
_Images = _AutoPlay.."\\Images";
_Plugins = _AutoPlay.."\\Plugins";
_Scripts = _AutoPlay.."\\Scripts";
_TempAPFolder = _AutoPlay.."\\Temp";
_Videos = _AutoPlay.."\\Videos";
end
end
if not Folder.DoesExist(_TempAPFolder) then
Folder.Create(_TempAPFolder);
end
--================================================== =========================
--========================== GLOBAL PATH SECTION END ========================
--================================================== =========================
Just put this into your On Startup section or run it On Startup from an external script (which is what I do);
presidente
12-25-2008, 10:12 PM
This little function detects in which mode (Web-exe, Harddrive-folder etc.) and where the program is running.
You can use the returned values to access the other folders, like docs etc.
Just put it in the global funktions tab and call it in Actions on startup.
function fnDetectMode(runexe)
resFile = File.Run(runexe, "", "", SW_SHOWNORMAL, false);
if _CommandLineArgs[1] ~= nil then
ModeStrPath = String.Replace(_CommandLineArgs[1], "SFXSOURCE:", "", true);
else
ModeStrPath = _SourceFolder.."\\".._SourceFilename;
end
mode_path = String.SplitPath(ModeStrPath);
return mode_path;
--[[
Now you can access the parameters of the path with
mode_path.Drive
mode_path.Folder
mode_path.Filename
mode_path.Extension
--]]
end
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.