clean up start directory too

This commit is contained in:
David Rose 2009-12-21 20:01:47 +00:00
parent 22beaad50d
commit e2a393cb57
4 changed files with 54 additions and 25 deletions

View File

@ -1361,6 +1361,15 @@ uninstall_packages() {
package->uninstall();
}
}
// Also clean up the start directory, if we have a custom start dir.
string start_dir_suffix = get_start_dir_suffix();
if (!start_dir_suffix.empty()) {
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
string start_dir = inst_mgr->get_root_dir() + "/start" + start_dir_suffix;
nout << "Cleaning up start directory " << start_dir << "\n";
inst_mgr->delete_directory_recursively(start_dir);
}
}
////////////////////////////////////////////////////////////////////
@ -2000,6 +2009,46 @@ get_host_info(P3DHost *host) {
// Didn't find an entry for this host; oh well.
}
////////////////////////////////////////////////////////////////////
// Function: P3DInstance::get_start_dir_suffix
// Access: Public
// Description: Determines the local path to the appropriate start
// directory for this instance, within the generic
// "start" directory. Returns empty string if this
// instance doesn't specify a custom start directory.
//
// If this is nonempty, it will begin with a slash--the
// intention is to append this to the end of the generic
// start_dir path.
////////////////////////////////////////////////////////////////////
string P3DInstance::
get_start_dir_suffix() const {
string start_dir_suffix;
string start_dir = get_fparams().lookup_token("start_dir");
if (start_dir.empty()) {
start_dir = _start_dir;
if (!start_dir.empty()) {
// If the start_dir is taken from the p3d file (and not from the
// HTML tokens), then we also append the alt_host name to the
// start_dir, so that each alt_host variant will run in a
// different directory.
string alt_host = get_fparams().lookup_token("alt_host");
if (!alt_host.empty()) {
start_dir += "_";
start_dir += alt_host;
}
}
}
if (!start_dir.empty()) {
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
inst_mgr->append_safe_dir(start_dir_suffix, start_dir);
}
return start_dir_suffix;
}
////////////////////////////////////////////////////////////////////
// Function: P3DInstance::send_browser_script_object
// Access: Private

View File

@ -175,6 +175,7 @@ private:
void add_packages();
string find_alt_host_url(const string &host_url, const string &alt_host);
void get_host_info(P3DHost *host);
string get_start_dir_suffix() const;
void send_browser_script_object();
P3D_request *make_p3d_request(TiXmlElement *xrequest);

View File

@ -132,7 +132,7 @@ shutdown() {
#ifdef _WIN32
// Wait for a certain amount of time for the process to stop by
// itself.
if (WaitForSingleObject(_p3dpython_handle, max_wait_ms) == WAIT_TIMEOUT) {
while (WaitForSingleObject(_p3dpython_handle, max_wait_ms) == WAIT_TIMEOUT) {
// It didn't shut down cleanly, so kill it the hard way.
nout << "Force-killing python process.\n";
TerminateProcess(_p3dpython_handle, 2);
@ -713,28 +713,7 @@ start_p3dpython(P3DInstance *inst) {
_keep_user_env = true;
}
if (!_keep_user_env) {
_start_dir = inst_mgr->get_root_dir() + "/start";
string start_dir = inst->get_fparams().lookup_token("start_dir");
if (start_dir.empty()) {
start_dir = inst->_start_dir;
if (!start_dir.empty()) {
// If the start_dir is taken from the p3d file (and not from the
// HTML tokens), then we also append the alt_host name to the
// start_dir, so that each alt_host variant will run in a
// different directory.
string alt_host = inst->get_fparams().lookup_token("alt_host");
if (!alt_host.empty()) {
start_dir += "_";
start_dir += alt_host;
}
}
}
if (!start_dir.empty()) {
inst_mgr->append_safe_dir(_start_dir, start_dir);
}
_start_dir = inst_mgr->get_root_dir() + "/start" + inst->get_start_dir_suffix();
mkdir_complete(_start_dir, nout);
}

View File

@ -445,8 +445,8 @@ make_window() {
int y = _wparams.get_win_y();
if (x == -1) x = CW_USEDEFAULT;
if (y == -1) y = CW_USEDEFAULT;
if (x == -2) x = 0.5 * (GetSystemMetrics(SM_CXBORDER) - width);
if (y == -2) y = 0.5 * (GetSystemMetrics(SM_CYBORDER) - height);
if (x == -2) x = (int)(0.5 * (GetSystemMetrics(SM_CXBORDER) - width));
if (y == -2) y = (int)(0.5 * (GetSystemMetrics(SM_CYBORDER) - height));
if (_wparams.get_window_type() == P3D_WT_embedded) {
// Create an embedded window.