Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*---------------------------------------------------------------------------
- Function: p2_dumpFile
- Author: [email protected]
- Description: Takes file path as input (relative to mission root)
- and outputs all of file contents regardless of file size
- Use Example:
- "init.sqf" call p2_dumpFile;
- ---------------------------------------------------------------------------*/
- p2_dumpFile = {
- //if you touch my script you can touch my privates too i guess
- private ["_p2_dumpFile_dbg", "_p2_dumpFile_splitSize", "_p2_dumpFile_log", "_inputScriptPath", "_scriptPathArr", "_scriptPathArrLen", "_endingChar", "_startingChar", "_splitTextPart", "_splitTextArr", "_splitCount", "_waitCounter"];
- //Config
- _p2_dumpFile_dbg = 2; //Debugging Setting: 0 = Nothing, 1 = Just Errors, 2 = Everything in logs
- _p2_dumpFile_cancelMode = 1; //0 = Off, 1 = If the function is called again, previous running versions of the function are ended without output
- //Expert config
- _p2_dumpFile_splitSize = 496; //Size to split by (dont change this m8)
- //Create log func
- _p2_dumpFile_log = {
- private["_in","_msg","_msgType"];
- _in = _this;
- _msgType = _in select 0; //MsgTypes: 0 = Error, 1 = Information
- _msg = _in select 1;
- switch (_msgType) do {
- case 0 : {
- if (_p2_dumpFile_dbg < 1) exitWith {0};
- diag_log(format["p2_dumpFile: %1",_msg]); 0
- };
- case 1 : {
- if (_p2_dumpFile_dbg > 1) exitWith { diag_log(format["p2_dumpFile: %1",_msg]); 0 };
- };
- default {
- diag_log(format["p2_dumpFile: %1",_msg]); 0
- };
- };
- 0
- };
- //Log info
- [1,format["Debugging Mode: %1", _p2_dumpFile_dbg]] call _p2_dumpFile_log;
- [1,format["Cancel Mode: %1", _p2_dumpFile_cancelMode]] call _p2_dumpFile_log;
- //Set Default Vars (default is mission file init)
- _inputScriptPath = "init.sqf";
- _scriptPathArr = toArray(_inputScriptPath);
- _scriptPathArrLen = count(_scriptPathArr);
- _endingChar = 0;
- _startingChar = 0;
- _splitTextPart = "";
- _splitTextArr = [];
- _splitCount = 0;
- _waitCounter = 0;
- //Check cancel mode
- if (_p2_dumpFile_cancelMode > 0) then {
- //Create vars
- if (isNil 'p2_dumpFile_running') then {
- p2_dumpFile_running = false;
- p2_dumpFile_exitInstance = false;
- };
- //If there is an instance of this func running, set global var to true so it exits
- if (p2_dumpFile_running) then {
- p2_dumpFile_exitInstance = true;
- [1,format["Existing Instance Running...Waiting for it to Quit..."]] call _p2_dumpFile_log;
- };
- //now wait for running to go to false, so we know the other instance quit and we can continue
- //this command is why we need to use spawn not call, since we cannot halt the thread in a call
- while {((p2_dumpFile_running) && (_waitCounter < 10))} do {
- _waitCounter = _waitCounter + 1;
- uiSleep 1;
- };
- [1,format["Existing Instance Finished Running...Lets get Started!"]] call _p2_dumpFile_log;
- //Set runing var to true
- p2_dumpFile_running = true;
- };
- //Get input path, set to init.sqf if error or blank string
- _inputScriptPath = _this;
- if (isNil '_inputScriptPath' || {typeName _inputScriptPath != "STRING" || {_inputScriptPath == ""}}) exitWith {
- //log the error
- [0,"Input Error - Quitting"] call _p2_dumpFile_log;
- //update the var
- p2_dumpFile_running = false;
- };
- //Get script contents and convert to array to avoid string limitations
- _scriptPathArr = toArray(preprocessfilelinenumbers _inputScriptPath);
- //Get array length (character count)
- _scriptPathArrLen = (count _scriptPathArr);
- //log the info
- [1,format["Input Script Path: %1", _inputScriptPath]] call _p2_dumpFile_log;
- [1,format["Input Script File Length: %1", _scriptPathArrLen]] call _p2_dumpFile_log;
- [1,format["Split Size: %1", _p2_dumpFile_splitSize]] call _p2_dumpFile_log;
- //Check if this even needs splitting
- if (_scriptPathArrLen >= _p2_dumpFile_splitSize) then {
- //Get split count
- _splitCount = round (_scriptPathArrLen / _p2_dumpFile_splitSize);
- //log the info
- [1,format["Split Count: %1", _splitCount]] call _p2_dumpFile_log;
- //For each split
- for "_i" from 1 to _splitCount do {
- //Check if exit instance has been set, in which case, we should quit now!
- if (p2_dumpFile_exitInstance) exitWith {
- //Log the info
- [1,format["Quitting...Another Instance has Started and Cancel Mode is 1!"]] call _p2_dumpFile_log;
- //set vars
- p2_dumpFile_exitInstance = false;
- p2_dumpFile_running = false;
- };
- //Multiply amount of splits done so far by _p2_dumpFile_splitSize to get which char to end with
- _endingChar = _i * _p2_dumpFile_splitSize;
- //Starting char is ending char - _p2_dumpFile_splitSize
- _startingChar = _endingChar - _p2_dumpFile_splitSize;
- //Log the info
- [1,format["Splitting from %1 to %2, chars left: %3, splits left: %4", _startingChar,_endingChar,_scriptPathArrLen - _startingChar,_splitCount - _i]] call _p2_dumpFile_log;
- //Get chars between starting and ending and also convert to string
- _splitTextPart = [_scriptPathArr,_startingChar,_endingChar] call {
- private["_inArr","_in","_pos","_len","_arr","_out"];
- _in = _this;
- _inArr= _in select 0;
- _pos=abs(_in select 1);
- _arr=[];
- for "_i" from 0 to (count _inArr)-1 do {
- _arr=_arr+[toString([_inArr select _i])];
- };
- _len=count(_arr);
- if ((count _in)>2) then {_len=(_in select 2)};
- _out="";
- if ((_pos+_len)>=(count _arr)) then {_len=(count _arr)-_pos};
- if (_len>0) then {
- for "_i" from _pos to (_pos+_len-1) do {
- _out=_out + (_arr select _i);
- };
- };
- _out
- };
- //Add part to array
- _splitTextArr set [count _splitTextArr, _splitTextPart];
- };
- //Check if exit instance has been set, in which case, we should quit now!
- if (p2_dumpFile_exitInstance) exitWith {
- //Log the info
- [1,format["Quitting...Another Instance has Started and Cancel Mode is 1!"]] call _p2_dumpFile_log;
- //set vars
- p2_dumpFile_exitInstance = false;
- p2_dumpFile_running = false;
- };
- //Output
- {
- //Check if exit instance has been set, in which case, we should quit now!
- if (p2_dumpFile_exitInstance) exitWith {
- //Log the info
- [1,format["Quitting...Another Instance has Started and Cancel Mode is 1!"]] call _p2_dumpFile_log;
- //set vars
- p2_dumpFile_exitInstance = false;
- p2_dumpFile_running = false;
- };
- diag_log(_x);
- } forEach _splitTextArr;
- } else {
- //Check if exit instance has been set, in which case, we should quit now!
- if (p2_dumpFile_exitInstance) exitWith {
- //Log the info
- [1,format["Quitting...Another Instance has Started and Cancel Mode is 1!"]] call _p2_dumpFile_log;
- //set vars
- p2_dumpFile_exitInstance = false;
- p2_dumpFile_running = false;
- };
- //Output
- diag_log(toString(_scriptPathArr));
- };
- p2_dumpFile_running = false;
- 0
- };
Add Comment
Please, Sign In to add comment