PROCESS.CPP 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. ** Command & Conquer Red Alert(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. bit8 Wait_Process(Process &process)
  45. {
  46. DWORD retval;
  47. retval=WaitForSingleObject(process.hProcess,INFINITE);
  48. if (retval==WAIT_OBJECT_0) // process exited
  49. return(TRUE);
  50. else // can this happen?
  51. return(FALSE);
  52. }
  53. //
  54. // Get the process to run from the config object
  55. //
  56. bit8 Read_Process_Info(ConfigFile &config,OUT Process &info)
  57. {
  58. Wstring procinfo;
  59. if (config.getString("RUN",procinfo)==FALSE)
  60. {
  61. DBGMSG("Couldn't read the RUN line");
  62. return(FALSE);
  63. }
  64. int offset=0;
  65. Wstring dir;
  66. Wstring executable;
  67. Wstring args;
  68. offset=procinfo.getToken(offset," ",dir);
  69. offset=procinfo.getToken(offset," ",executable);
  70. args=procinfo;
  71. args.remove(0,offset);
  72. ///
  73. ///
  74. DBGMSG("RUN: EXE = "<<executable.get()<<" DIR = "<<dir.get()<<
  75. " ARGS = "<<args.get());
  76. strcpy(info.command,executable.get());
  77. strcpy(info.directory,dir.get());
  78. strcpy(info.args,args.get());
  79. return(TRUE);
  80. /*********************************************************
  81. FILE *in;
  82. char string[256];
  83. bit8 found_space;
  84. int i;
  85. if ((in=fopen(config,"r"))==NULL)
  86. return(FALSE);
  87. while(fgets(string,256,in))
  88. {
  89. i=0;
  90. while ((isspace(string[i]))&&(i<int(strlen(string))))
  91. i++;
  92. // do nothing with empty line or commented line
  93. if ((string[i]=='#')||(i==int(strlen(string)-1)))
  94. continue;
  95. strcpy(info.directory,string);
  96. found_space=FALSE;
  97. for (; i<int(strlen(string)); i++)
  98. {
  99. if (isspace(info.directory[i]))
  100. {
  101. info.directory[i]=0;
  102. found_space=TRUE;
  103. }
  104. else if (found_space)
  105. break;
  106. }
  107. strcpy(info.command,string+i);
  108. for (i=0; i<int(strlen(info.command)); i++)
  109. if ((info.command[i]=='\n')||(info.command[i]=='\r'))
  110. info.command[i]=0;
  111. //printf("DIR = '%s' CMD = '%s'\n",info.directory,info.command);
  112. // We only have 1 process for this
  113. break;
  114. }
  115. fclose(in);
  116. return(TRUE);
  117. **********************************************/
  118. }