PROCESS.CPP 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "process.h"
  19. Process::Process()
  20. {
  21. directory[0]=0;
  22. command[0]=0;
  23. args[0]=0;
  24. hProcess=NULL;
  25. hThread=NULL;
  26. }
  27. // Create a process
  28. bit8 Create_Process(Process &process)
  29. {
  30. int retval;
  31. STARTUPINFO si;
  32. PROCESS_INFORMATION piProcess;
  33. ZeroMemory(&si,sizeof(si));
  34. si.cb=sizeof(si);
  35. char cmdargs[513];
  36. memset(cmdargs,0,513);
  37. strcpy(cmdargs,process.command);
  38. strcat(cmdargs,process.args);
  39. retval=CreateProcess(NULL,cmdargs,NULL,NULL,FALSE, 0 ,NULL, NULL/*process.directory*/,&si,&piProcess);
  40. process.hProcess=piProcess.hProcess;
  41. process.hThread=piProcess.hThread;
  42. return(TRUE);
  43. }
  44. //
  45. // Wait for a process to complete, and fill in the exit code
  46. //
  47. bit8 Wait_Process(Process &process, DWORD *exit_code)
  48. {
  49. DWORD retval;
  50. retval=WaitForSingleObject(process.hProcess,INFINITE);
  51. if (exit_code != NULL)
  52. *exit_code=-1;
  53. if (retval==WAIT_OBJECT_0) // process exited
  54. {
  55. if (exit_code != NULL)
  56. GetExitCodeProcess(process.hProcess,exit_code);
  57. return(TRUE);
  58. }
  59. else // can this happen?
  60. return(FALSE);
  61. }
  62. /*******************
  63. //
  64. // Get the process to run from the config object
  65. //
  66. bit8 Read_Process_Info(ConfigFile &config,OUT Process &info)
  67. {
  68. Wstring procinfo;
  69. if (config.getString("RUN",procinfo)==FALSE)
  70. {
  71. DBGMSG("Couldn't read the RUN line");
  72. return(FALSE);
  73. }
  74. int offset=0;
  75. Wstring dir;
  76. Wstring executable;
  77. Wstring args;
  78. offset=procinfo.getToken(offset," ",dir);
  79. offset=procinfo.getToken(offset," ",executable);
  80. args=procinfo;
  81. args.remove(0,offset);
  82. ///
  83. ///
  84. DBGMSG("RUN: EXE = "<<executable.get()<<" DIR = "<<dir.get()<<
  85. " ARGS = "<<args.get());
  86. strcpy(info.command,executable.get());
  87. strcpy(info.directory,dir.get());
  88. strcpy(info.args,args.get());
  89. return(TRUE);
  90. }
  91. *****************/