Beispiel #1
0
Tmainwin::~Tmainwin()
{
	addlog(_text("Destroying all existing display windows"),+1);
	Tcopyarray<TDisplayWindow> *wins=G_displaywindows();
	for (int i=0; i<wins->G_count(); i++)
		wins->get(i)->DestroyWindow();
	addlog(_text("All existing display windows are destroyed"),-1);


	addlog(_text("Saving open scripts list"),+1);
	QTextfile fl;
	QString filename,st;
	FormatString(filename,_qstr("^1\\openscripts.txt"),G_datadir());
	fl.openwrite(filename);
	FormatString(st,_qstr("^1"),G_sourcetabbar()->G_curtab());
	fl.write(st);fl.writeline();
	for (int i=0; i<scripts.G_count(); i++)
	{
		fl.write(scripts[i]->G_source().G_filename());
		fl.writeline();
	}
	fl.close();

	addlog(_text("Open scripts list saved"),-1);

	addlog(_text("Closing log file"));
	logfilestarted=false;
}
Beispiel #2
0
T3DGeoObjectPreCalcMesh::T3DGeoObjectPreCalcMesh(T3DScene *iscene) : T3DGeoObject(iscene)
{
	iscalculated=false;
	canbuffer=addparam(_qstr("CanBuffer"),SC_valname_boolean,false,_text("Uses Vertex Buffer Objects (accelerates for complex objects)"),_text("Optimization"))->content.G_content_boolean();
	canbuffer->copyfrom(false);

	calcedges=addparam(_qstr("CalculateEdges"),SC_valname_boolean,false,_text("Determines whether or not the edges are calculated (needed for volume shadows)"),_text("Optimization"))->content.G_content_boolean();

}
Beispiel #3
0
void initlog()
{
	logfilename=datadir+_qstr("/log.txt");
	FILE *fp=_wfopen(logfilename,_qstr("w"));
	if (fp==NULL)
	{
		reporterror(TFormatString(_text("Unable to create log file ^1"),logfilename));
		logfilename="";
	}
	fclose(fp);
	addlog(_text("================================= START LOG FILE ========================================"));
	logfilestarted=true;
}
Beispiel #4
0
void ExecuteApplication(StrPtr commandline, StrPtr startupdir, bool waitforcompletion)
{

	STARTUPINFO si;
	PROCESS_INFORMATION pi;

	ZeroMemory( &si, sizeof(si) );
	si.cb = sizeof(si);
	ZeroMemory( &pi, sizeof(pi) );
	// Start the child process.
	if( !CreateProcess( NULL, // No module name (use command line).
		(StrChar*)commandline, // Command line.
		NULL,             // Process handle not inheritable.
		NULL,             // Thread handle not inheritable.
		FALSE,            // Set handle inheritance to FALSE.
		0,                // No creation flags.
		NULL,             // Use parent's environment block.
		startupdir,       // Startup directory
		&si,              // Pointer to STARTUPINFO structure.
		&pi )             // Pointer to PROCESS_INFORMATION structure.
	) throw QError(TFormatString(_text("Unable to start application '^1'"),commandline));

	if (waitforcompletion)
	{
		// Wait until child process exits.
		WaitForSingleObjectEx(pi.hThread,INFINITE,TRUE);
	}

	// Close process and thread handles.
	CloseHandle( pi.hProcess );
	CloseHandle( pi.hThread );
}
Beispiel #5
0
	NSHARE::CText process_name(int processID)
	{
		TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");

		// Get a handle to the process.
		HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
				FALSE, processID);

		// Get the process name.
		if (INVALID_HANDLE_VALUE != hProcess)
		{
			HMODULE hMod;
			DWORD cbNeeded;

			//Given a handle to a process, this returns all the modules running within the process.
			//The first module is the executable running the process,
			//and subsequent handles describe DLLs loaded into the process.
			if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
			{
				//This function returns the short name for a module,
				//typically the file name portion of the EXE or DLL
				GetModuleBaseName(hProcess, hMod, szProcessName,
						sizeof(szProcessName) / sizeof(TCHAR));
			}
		}
		NSHARE::CText _text(szProcessName);
		//close the process handle
		CloseHandle(hProcess);
		return _text;
	}
Beispiel #6
0
void GetObjectName(TSC_value *val, QString &name)
{
	QString error;
	name.clear();
	if ((val==NULL)||(val->G_datatype()==NULL)) return;
	TSC_value retval;
	TSC_funcarglist arglist(NULL);
	if (val->G_datatype()==NULL)
		throw QError(_text("Unable to get object name: no data type specified"));
	if (!val->G_datatype()->evalmemberfunction(val->G_content(),_qstr("name"),&retval,NULL,arglist,error))
	{
		QString err;FormatString(err,_text("Unable to get object name for type ^1"),val->G_datatype()->G_name());
		throw QError(err);
	}
	name=retval.G_content_string()->G_string();
}
Beispiel #7
0
void Tmainwin::cmd_stepscript()
{
	if (G_curscript()==NULL)
	{
		reporterror(this,_text("There is no script present"));
		return;
	}
	scriptaction_pre();
	QString error;
	if (!G_curscript()->exec_isstarted())
	{
		if (!G_curscript()->exec_start(error))
		{
			scriptaction_post();
			scriptsourceview->scrollinside_sel();
			reporterror(this,error);
		}
		scriptaction_post();
	}
	else
	{
		if (!G_curscript()->exec_stepone(error)) reporterror(this,error);
		scriptaction_post();
	}
}
Beispiel #8
0
void LuckLayer::update(float dt)
{
	m_interval += dt;
	m_totalTime -= dt;
	if (m_interval > 0.1)
	{
		m_interval = 0;
		m_awardIndex = (m_awardIndex + 1) % 6;
		
		m_light->setPosition(m_items[m_awardIndex]->getParent()->convertToWorldSpace(m_items[m_awardIndex]->getPosition()));

		if (m_totalTime <= 0)
		{
			if (m_awardIndex < 3)
				m_awardIndex += 3;

			if (m_isFirstLucy)
			{
				CCUserDefault::sharedUserDefault()->setBoolForKey("firstlucky",false);
				m_awardIndex = 5;
			}
			m_light->setPosition(m_items[m_awardIndex]->getParent()->convertToWorldSpace(m_items[m_awardIndex]->getPosition()));
			this->unscheduleUpdate();
			m_label->setText(_text("lingqu"));
		}

	}
}
Beispiel #9
0
void Tmainwin::openactivescripts()
{
	addlog(_text("Opening active scripts"),+1);
	TQXpanel *sourcepanel=G_panel_byname(_qstr("Source"));
	if (sourcepanel==NULL)
	{
		ASSERT(false);
		return;
	}
	sourcepanel->customtabs_init(scriptsourceview);

	try{
		QTextfile fl;
		QString filename,line;
		FormatString(filename,_qstr("^1\\openscripts.txt"),G_datadir());
		fl.openread(filename);
		fl.readline(line);
		int activescriptnr=qstr2int(line);
		while(!fl.isend())
		{
			fl.readline(line);
			if (line.G_length()>0)
			{
				try{
					TSC_script *script1=new TSC_script(&GetTSCenv());
					script1->G_source().load(line);
					scripts.add(script1);
					sourcepanel->customtabs_add(script1->G_source().G_filename());
				} catch(QError err)
				{
					QString errstr;
					FormatString(errstr,_text("Unable to open script file ^1: ^2"),line,err.G_content());
					reporterror(errstr);
				}
			}
		}
		fl.close();
		if ((activescriptnr>=0)&&(activescriptnr<scripts.G_count()))
			G_sourcetabbar()->change_tab(activescriptnr);
		else
			scriptsourceview->Set_script(scripts[0]);
		addlog(_text("Active scripts opened"),-1);
	} catch(QError &err)
	{
		reporterror(err.G_content());
	}
}
Beispiel #10
0
void TSC_value::streamin_withtype(QBinTagReader &reader)
{
	QString datatypename;
	reader.read_shortstring(datatypename);
	TSC_datatype *dtpe=GetTSCenv().G_datatype(datatypename);
	if (dtpe==NULL) throw QError(TFormatString(_text("Unrecognised data type ^1"),datatypename));
	createtype(dtpe);
	streamin(reader);
}
Beispiel #11
0
void reporttimer(StrPtr content)
{
	DWORD newtick=GetTickCount();
	if (newtick<lasttick+60*1000)
	{
		message(TFormatString(_text("^1 ^2s"),content,(newtick-lasttick)/1000.0));
	}
	lasttick=GetTickCount();
}
Beispiel #12
0
T3DControl_Menu::T3DControl_Menu(T3DScene *iscene, bool addtocontrols) : T3DControl(iscene,addtocontrols) , root(NULL)
{
	sizex=addparam(_qstr("SizeX"),SC_valname_scalar)->content.G_content_scalar();
	selectid=addparam(_qstr("SelectID"),SC_valname_string)->content.G_content_string();

	addparam(_qstr("Texture"),SC_valname_string,false,_text(""),PARAMSUBCLASS_APPEARANCE);

	root.cursubsel=0;

}
Beispiel #13
0
void loadstockcyclorbits()
{

	Tcyclorbit2 *orb;
	QString filename;

	addlog(_text("Loading stock cyclic orbits"),+1);

	filename=G_datadir();filename+=_text("/AstroData/MERCURIUS_cycl.tab");
	orb=new Tcyclorbit2(filename,0.00001,au2km);
	stockcyclorbits.add(orb);stockcyclorbitnames.add(new QString("MERCURIUS"));

	filename=G_datadir();filename+=_text("/AstroData/VENUS_cycl.tab");
	orb=new Tcyclorbit2(filename,0.00001,au2km);
	stockcyclorbits.add(orb);stockcyclorbitnames.add(new QString("VENUS"));

	filename=G_datadir();filename+=_text("/AstroData/EARTH_cycl.tab");
	orb=new Tcyclorbit2(filename,0.00001,au2km);stockcyclorbitnames.add(new QString("EARTH"));
	stockcyclorbits.add(orb);

	filename=G_datadir();filename+=_text("/AstroData/MARS_cycl.tab");
	orb=new Tcyclorbit2(filename,0.00001,au2km);
	stockcyclorbits.add(orb);stockcyclorbitnames.add(new QString("MARS"));

	filename=G_datadir();filename+=_text("/AstroData/JUPITER_cycl.tab");
	orb=new Tcyclorbit2(filename,0.00001,au2km);
	stockcyclorbits.add(orb);stockcyclorbitnames.add(new QString("JUPITER"));

	filename=G_datadir();filename+=_text("/AstroData/SATURNUS_cycl.tab");
	orb=new Tcyclorbit2(filename,0.00001,au2km);
	stockcyclorbits.add(orb);stockcyclorbitnames.add(new QString("SATURNUS"));

	filename=G_datadir();filename+=_text("/AstroData/URANUS_cycl.tab");
	orb=new Tcyclorbit2(filename,0.00001,au2km);
	stockcyclorbits.add(orb);stockcyclorbitnames.add(new QString("URANUS"));

	filename=G_datadir();filename+=_text("/AstroData/NEPTUNUS_cycl.tab");
	orb=new Tcyclorbit2(filename,0.00001,au2km);
	stockcyclorbits.add(orb);stockcyclorbitnames.add(new QString("NEPTUNUS"));


	addlog(_text("Stock cyclic orbits loaded"),-1);
}
Beispiel #14
0
void execute_implement(TSC_funcarglist *arglist, TSC_value *retval, TSC_value *assigntoval, TSC_value *owner)
{
	T3DControl_Menu *menu=G_valuecontent<T3DControl_Menu>(owner);
	QString id=arglist->get(0)->G_content_string()->G_string();
	T3DControl_Menu_Item *item=menu->root.finditem(id);
	if (item==NULL) throw QError(_text("Invalid menu item ID"));
	if (assigntoval!=NULL)
		item->checked=assigntoval->G_content_boolean()->G_val();
	retval->G_content_boolean()->copyfrom(item->checked);
}
Beispiel #15
0
bool Tmainwin::DoClose()
{
	for (int i=0; i<scripts.G_count(); i++)
	{
		if (scripts[i]->G_source().G_ismodified())
		{
			G_sourcetabbar()->change_tab(i);
			QString st;
			FormatString(st,_text("Script '^1' has been modified. Do you want to save it now?"),scripts[i]->G_source().G_filename());
			int rs=MessageBox(st,_text("Warning"),MB_ICONQUESTION|MB_YESNOCANCEL);
			if (rs==IDCANCEL) return false;
			if (rs==IDYES)
			{
				cmd_savescript();
				if (scripts[i]->G_source().G_ismodified()) return false;
			}
		}
	}
	return true;
}
Beispiel #16
0
void Tmainwin::cmd_stopscript()
{
	if (G_curscript()==NULL)
	{
		reporterror(this,_text("There is no script present"));
		return;
	}
	G_curscript()->exec_stop();
	scriptsourceview->redraw();
	scriptvarview->redraw();
}
Beispiel #17
0
Tcyclorbit2::Tcyclorbit2(StrPtr ifilename, double accuracy, double iscalefactor)
{
	try{
		FILE *fp;
		char termtype[1000];
		int order;
		double A,B,C;

		addlog(TFormatString(_text("Loading stock cyclic orbit ^1"),ifilename));

		scalefactor=iscalefactor;
		if (_wfopen_s(&fp,ifilename,_qstr("r"))!=0) throw QError(TFormatString(_text("Unable to find cycl file ^1"),ifilename));

		expa_L.reset(accuracy);
		expa_B.reset(accuracy);
		expa_R.reset(accuracy/100.0);

		//preset for L & B
		expa_L.maxA=2*Pi*accuracy;expa_L.fixedaccuracy=true;
		expa_B.maxA=2*Pi*accuracy;expa_B.fixedaccuracy=true;

		expa_R.maxA=1.0;

		bool ok=true;
		for(;(ok)&&(!feof(fp));)
		{
			if (fscanf(fp,"%s %d %lf %lf %lf\n",termtype,&order,&A,&B,&C)==5)
			{
				if (stricmp(termtype,"L")==0) expa_L.try_addterm(order,A,B,C);
				if (stricmp(termtype,"B")==0) expa_B.try_addterm(order,A,B,C);
				if (stricmp(termtype,"R")==0) expa_R.try_addterm(order,A,B,C);
			}
		}
		fclose(fp);
	}
	catch(QError &err)
	{
		reporterror(err.G_content());
	}
}
Beispiel #18
0
void Tmainwin::cmd_addobject(int objnr)
{
	ASSERT((objnr>=0)&&(objnr<T3DCosmos::Get().G_objectcatalog_count()));
	if (objtreeview->G_cursor()==NULL)
	{
		MessageBox(_text("No object is selected"),_text("Error"),MB_ICONEXCLAMATION|MB_OK);
		return;
	}
	T3DScene *selscene=T3DCosmos::Get().findscene(objtreeview->G_cursor());
	T3DObject *selobj=T3DCosmos::Get().findobject(objtreeview->G_cursor());
	if ((selobj==NULL)&&(selscene==NULL))
	{
		MessageBox(_text("The current selection is not an object or a scene"),_text("Error"),MB_ICONEXCLAMATION|MB_OK);
		return;
	}
	if ((selobj!=NULL)&&(!selobj->G_acceptsubobjects()))
	{
		MessageBox(_text("The selected object does not allow subobjects"),_text("Error"),MB_ICONEXCLAMATION|MB_OK);
		return;
	}
	T3DObject *newobj=T3DCosmos::Get().G_objectcatalog_object(objnr)->MakeInstance();
	if (selobj!=NULL) selobj->addsubobject(newobj);
	if (selscene!=NULL) selscene->addobject(newobj);
	objtreeview->Set_cursor(newobj);
	objtreeview->redraw();
	objtreeview->updatescrollbars();
	return;
}
Beispiel #19
0
void T2DContourset::generate(TSC_functor *functor, double minv, double maxv, int count)
{
	if (count<2) throw QError(_qstr("Generate contour: invalid number of points"));

	try{
		double vl,vl1,vl2,dff;
		Tvertex pt,pt1,pt2;
		Tvector tangent,norm;
		TSC_funcarglist arglist(NULL);
		TSC_value retval0,arg;
		arg.createtype(GetTSCenv().G_datatype(SC_valname_scalar));
		arglist.add(&arg);
		dff=(maxv-minv)/count/50;
		for (int i=0; i<count; i++)
		{
			vl=minv+(maxv-minv)*i/(count-1.0);
			vl1=vl-dff/2;
			vl2=vl+dff/2;
			arg.copyfrom(vl);functor->eval(&arglist,&retval0);pt=*G_valuecontent<Tvertex>(&retval0);
			arg.copyfrom(vl1);functor->eval(&arglist,&retval0);pt1=*G_valuecontent<Tvertex>(&retval0);
			arg.copyfrom(vl2);functor->eval(&arglist,&retval0);pt2=*G_valuecontent<Tvertex>(&retval0);
			tangent.subtr(&pt2,&pt1);
			norm.vecprod(&tangent,&Tvector(0,0,1));norm.normfrom(&norm);
			addpoint(&pt,&norm);
		}
	}
	catch(TSC_runerror err)
	{
		QString errstring;
		FormatString(errstring,_text("Generate contour: ^1"),err.G_content());
		throw QError(errstring);
	}
	catch(QError err)
	{
		QString errstring;
		FormatString(errstring,_text("Generate contour: ^1"),err.G_content());
		throw QError(errstring);
	}
}
Beispiel #20
0
void T2DContour::addpoint(int PTID, Tvertex *pt, Tvector *nm)
{
	if (closed) throw QError(_text("Unable to add points to an already closed contour"));
	T2DContourPoint cpt;
	cpt.pt=*pt;
	cpt.PTID=PTID;
	if (nm!=NULL)
	{
		cpt.normalpresent=true;
		cpt.nm=*nm;
	}
	else cpt.normalpresent=false;
	points.add(cpt);
}
Beispiel #21
0
void T3DControl_Menu::additem(StrPtr iID, StrPtr iname, StrPtr parentid, bool cancheck)
{
	T3DControl_Menu_Item *parent=&root;
	if (qstrlen(parentid)>0)
	{
		parent=root.finditem(parentid);
		if (parent==NULL)
		{
			QString err;FormatString(err,_text("Invalid parent menu ID '^1'"),parentid);
			throw QError(err);
		}
	}
	parent->additem(iID,iname,cancheck);
}
Beispiel #22
0
long _stdcall exceptfilter(_EXCEPTION_POINTERS *info)
{
	LONG retval=EXCEPTION_CONTINUE_SEARCH;

	//load dbghelp module
	HMODULE hdll=NULL;
	StrChar debughelppath[1999];
	if (GetModuleFileName(NULL,debughelppath,999))
	{
		StrChar *pslash=_tcsrchr(debughelppath,'\\');
		if (pslash)
		{
			_tcscpy_s(pslash+1,999,_qstr("DBGHELP.DLL"));
			hdll=::LoadLibrary(debughelppath);
		}
	}
	if (hdll==NULL) hdll=::LoadLibrary(_qstr("DBGHELP.DLL"));

	QString dumpcomment,dumppath;

	if (hdll==NULL) dumpcomment=_text("Could not write dump: unable to find DBGHELP.DLL");
	else
	{
		MINIDUMPWRITEDUMP pdump = (MINIDUMPWRITEDUMP)::GetProcAddress( hdll, "MiniDumpWriteDump" );
		if (pdump==NULL) strcpy(dumpcomment,"Could not write dump: too old version of DBGHELP.DLL");
		else
		{
			dumppath=_qstr("except.dmp");
			HANDLE hfile=::CreateFile(dumppath,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
			if (hfile==NULL) FormatString(dumpcomment,_text("Could not write dump: unable to save file '^1'"),dumppath);
			else
			{
				_MINIDUMP_EXCEPTION_INFORMATION ExInfo;
				ExInfo.ThreadId=::GetCurrentThreadId();
				ExInfo.ExceptionPointers=info;
				ExInfo.ClientPointers=NULL;
				BOOL ok=pdump(GetCurrentProcess(),GetCurrentProcessId(),hfile,MiniDumpNormal,&ExInfo,NULL,NULL);
				if (!ok) FormatString(dumpcomment,_text("Failed to save dump file to '^1'"),dumppath);
				else
				{
					FormatString(dumpcomment,_text("Saved dump file to '^1'"),dumppath);
					retval=EXCEPTION_EXECUTE_HANDLER;
				}
				::CloseHandle(hfile);
			}
		}
	}

	QString dumpinfo;
	dumpinfo=_text("An unrecoverable error occurred.\n");dumpinfo+=dumpcomment;
	::MessageBox(0,dumpinfo,_text("Error"),MB_TASKMODAL|MB_ICONSTOP|MB_OK);

	return retval;
}
Beispiel #23
0
void T3DObjectClock::render_exec_calendar(Trendercontext *rc, TSC_time &disptime, double size)
{
	try{
		QString content,monthstring;

		monthnames->get(disptime.G_month()-1)->tostring(monthstring,0);

		FormatString(content,_qstr("^1 "),disptime.G_day());
		content+=_TRL(monthstring);

		render_exec_string(rc,content);
	}
	catch(QError &)
	{
		throw QError(_text("Error while constructing calendar info"));
	}
}
Beispiel #24
0
bool LuckLayer::init()
{

	CCLayer::init();
	TouchGroup* m_pUiLayer = TouchGroup::create();
//	UILayer *m_pUiLayer = UILayer::create();
	addChild(m_pUiLayer);
	m_isFirstLucy = CCUserDefault::sharedUserDefault()->getBoolForKey("firstlucky",true);





	Layout* m_pPanel = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("giftlayer/choujiang.json"));

	m_pUiLayer->addWidget(m_pPanel);

	UIImageView * item = dynamic_cast<UIImageView*> (m_pPanel->getChildByName("item"));

	for (int i = 0; i < 6;i++)
	{
		char name[40];

		sprintf(name,"item%02d",i+1);
		m_items[i] = dynamic_cast<UIImageView*>(item->getChildByName(name));

	}

	UIImageView * back = dynamic_cast<UIImageView*>(m_pPanel->getChildByName("back"));
	UIImageView * sure = dynamic_cast<UIImageView*>(m_pPanel->getChildByName("sure"));
	back->setVisible(false);
	m_label = dynamic_cast<UILabel*>(m_pPanel->getChildByName("tip"));
	m_light = dynamic_cast<UIImageView*>(m_pPanel->getChildByName("light"));

	m_label->setText(_text("tip"));
	back->addTouchEventListener(this, SEL_TouchEvent(&LuckLayer::onBackClick));
	sure->addTouchEventListener(this, SEL_TouchEvent(&LuckLayer::onSureClick));
	m_awardIndex = -1;

	m_interval = 0.0;
	m_totalTime = 5.0;
	return true;
}
Beispiel #25
0
void Tmainwin::cmd_runscript()
{
	if (G_curscript()==NULL)
	{
		reporterror(this,_text("There is no script present"));
		return;
	}
	G_3DCosmos().Reset_requeststop();
	QString error;
	scriptaction_pre();
	if (!exec_run(error))
//	if (!G_curscript()->exec_run(error))
	{
		scriptaction_post();
		scriptsourceview->scrollinside_sel();
		reporterror(this,error);
	}
	else scriptaction_post();
}
Beispiel #26
0
void T3DGeoObject::render_drawobject(Trendercontext *rc, const TObjectRenderStatus *status, bool isrecording)
{
	if (G_cancache()&&(!isrecording)&&(displaylist!=NULL)&&(!G_needrecache()))
	{//draw display list
		displaylist->draw();
	}
	else
	{//explicit render
		if (displaylist!=NULL) rc->ForgetDisplayList(displaylist);displaylist=NULL;
		if (G_cancache()&&(!isrecording))
		{
			displaylist=rc->CreateDisplayList();
			displaylist->startrecord();
		}
		render_exec(rc);
		if (displaylist!=NULL) displaylist->endrecord();
		isdirty=false;
	}
	rc->checkerror(_text("End render_drawobject"));
}
Beispiel #27
0
void ShutDownWindows()
{
//	adderror("Starting system restart");


	HANDLE hToken; // handle to process token 
	TOKEN_PRIVILEGES tkp; // pointer to token structure 
	OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken); 
	// Get the LUID for shutdown privilege. 
	LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid); 
	tkp.PrivilegeCount = 1; // one privilege to set 
	// Get shutdown privilege for this process. 
	tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	AdjustTokenPrivileges(hToken,FALSE, &tkp,0,(PTOKEN_PRIVILEGES) NULL, 0); 
	// Cannot test the return value of AdjustTokenPrivileges.
	if(GetLastError()!= ERROR_SUCCESS) 
	{
//		adderror("AdjustTokenPrivileges enable failed.");
		return;
	}

	if (!InitiateSystemShutdown(NULL,_text("Shutdown by software"),0,true,false))
	{
/*		unsigned long lasterror=GetLastError();
		char css[1000];
		sprintf(css,"System shutdown failed: code %d",lasterror);
		adderror(css);
		char *mess=NULL;
		int rs;
		rs=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ARGUMENT_ARRAY,
						   NULL,lasterror,LANG_NEUTRAL,(LPTSTR)&mess,0,NULL );
		if (mess!=NULL)
		{
			adderror(mess);
			LocalFree(mess);
		}*/
		return;
	}
//	adderror("System shutdown executed");
	_exit(-1);
}
Beispiel #28
0
bool Tmainwin::exec_run(QString &cerror)
{
	TSC_script *curscript=G_curscript();
	if (curscript==NULL)
	{
		cerror=_text("There is no script present");
		return false;
	}

	if (!curscript->exec_isstarted())
	{
		if (!curscript->exec_start(cerror)) return false;
	}
	curscript->exec_clearbreak();
	while ((!curscript->exec_isfinished())&&(!curscript->G_exec_isbreak())&&(!G_3DCosmos().G_requeststop()))
	{
		exec_pumpmessage();
		if (!curscript->exec_stepone(cerror)) return false;
	}
	return true;
}
Beispiel #29
0
Tlunaorbit::Tlunaorbit()
{
	FILE *fp;
	int  i;
	char css[1000];

	QString filename=G_datadir();
	filename+=_qstr("\\AstroData\\moon.tab");

	if (_wfopen_s(&fp,filename,_qstr("r"))!=0) throw QError(_text("Unable to find moon.tab file"));
	fscanf(fp,"%s %d",css,&term1count);
	if (strcmp(css,"TAB1")!=0)
		{ _exit(0); }
	for (i=1; i<=term1count; i++)
	{
		fscanf(fp,"%d %d %d %d %d %d",
		&term1[i].i1,
		&term1[i].i2,
		&term1[i].i3,
		&term1[i].i4,
		&term1[i].j1,
		&term1[i].j2);
	}
	fscanf(fp,"%s %d",css,&term2count);
	if (strcmp(css,"TAB2")!=0)
		{ _exit(0); }
	for (i=1; i<=term2count; i++)
	{
		fscanf(fp,"%d %d %d %d %d",
		&term2[i].i1,
		&term2[i].i2,
		&term2[i].i3,
		&term2[i].i4,
		&term2[i].j1);
	}

	fclose(fp);
}
Beispiel #30
0
void Tmainwin::cmd_loadscript()
{
	OPENFILENAME openf;
	StrChar filters[10000],filename[30000],filetitle[30000];
	int i,sz;

	_tcscpy_s(filters,9999,_qstr("Script files (*.SCI)|*.SCI||"));
	sz=qstrlen(filters);
	for (i=0; i<=sz; i++) if (filters[i]=='|') filters[i]=0;
	for (i=0; i<=15999; i++) filename[i]=0;
	for (i=0; i<=15999; i++) filename[i]=0;

	openf.lStructSize=sizeof(openf);
	openf.hwndOwner=m_hWnd;
	openf.lpstrFilter=filters;
	openf.lpstrCustomFilter=NULL;
	openf.nMaxCustFilter=0;
	openf.nFilterIndex=1;
	openf.lpstrFile=filename;
	openf.nMaxFile=29999;
	openf.lpstrFileTitle=filetitle;
	openf.nMaxFileTitle=29999;
	openf.lpstrInitialDir=_qstr("");
	openf.lpstrTitle=_text("Load script file");
	openf.Flags=OFN_LONGNAMES|OFN_LONGNAMES|OFN_EXPLORER;
	openf.lpstrDefExt=_qstr("SCI");
	openf.lpfnHook=NULL;
	openf.lpTemplateName=0;

	if (GetOpenFileName(&openf)==TRUE)
	{
		TSC_script *script=new TSC_script(&GetTSCenv());
		script->G_source().load(filename);
		scripts.add(script);
		G_sourcetabbar()->addtab(scripts[scripts.G_count()-1]->G_source().G_filename());
		G_sourcetabbar()->change_tab(scripts.G_count()-1);
	}
}