//---------------------------------------------------------------------------
void __fastcall TRelDirSearchForm::GetFileList(AnsiString path, int baselen)
{
	TSearchRec r;
	int done;

	done=FindFirst(path + "*.*" ,faAnyFile, r);
	try
	{
		while(!done)
		{
			if(r.FindData.cFileName[0]!='.')
			{
				if(! (r.Attr & faDirectory))
				{
					// a file
					AnsiString name = AnsiString(path.c_str()+ baselen) +
						r.FindData.cFileName;
					FileList->Add(name);
					CurrentLabel->Caption = name;
					AnsiString fileext = ExtractFileExt(r.FindData.cFileName);
					ExtList->Add(fileext);

					// message processing
					Application->ProcessMessages();
					if(Aborted)
					{
						throw EAbort("Aborted");  // raise an aborting exception
					}
				}
				else
				{
					// a directory
					if(r.Name != "." && r.Name != ".." &&
						!(r.Name == "CVS" &&
							FileExists(path + AnsiString("CVS\\Repository"))))
								// ignoring CVS meta-data directory
					{
						GetFileList(path  + r.FindData.cFileName+
							AnsiString("\\"), baselen);
					}
				}
			}
			done=FindNext(r);
		}
	}
	catch(Exception &e)
	{
		FindClose(r);
		throw Exception(e);
	}
	FindClose(r);
}
void RethrowException(Exception * E)
{
  // this list has to be in sync with ExceptionMessage
  if (isa<EFatal>(E))
  {
    throw EFatal(E, L"");
  }
  else if (isa<ECallbackGuardAbort>(E))
  {
    throw ECallbackGuardAbort();
  }
  else if (isa<EAbort>(E))
  {
    throw EAbort(E->Message);
  }
  else if (WellKnownException(E, nullptr, nullptr, nullptr, true))
  {
    // noop, should never get here
  }
  else
  {
    throw ExtException(E, L"");
  }
}
Exemple #3
0
void RethrowException(Exception * E)
{
  // this list has to be in sync with ExceptionMessage
  if (NB_STATIC_DOWNCAST(EFatal, E) != nullptr)
  {
    throw EFatal(E, L"");
  }
  else if (NB_STATIC_DOWNCAST(ECallbackGuardAbort, E) != nullptr)
  {
    throw ECallbackGuardAbort();
  }
  else if (NB_STATIC_DOWNCAST(EAbort, E) != nullptr)
  {
    throw EAbort(E->Message);
  }
  else if (WellKnownException(E, nullptr, nullptr, nullptr, true))
  {
    // noop, should never get here
  }
  else
  {
    throw ExtException(E, L"");
  }
}
void Abort()
{
  throw EAbort(L"");
}
Exemple #5
0
void TVPBeforeSystemInit()
{
	RegisterDllLoadHook();
		// register DLL delayed import hook to support _inmm.dll

	TVPInitProgramArgumentsAndDataPath(false); // ensure command line

#ifdef TVP_REPORT_HW_EXCEPTION
	__dee_hacked_set_getExceptionObjectHook(TVP__dee_hacked_getExceptionObjectHook);
		// register hook function for hardware exceptions
#endif

	Application->HintHidePause = 24*60*60*1000;
		// not to hide tool tip hint immediately
	Application->ShowHint = false;
	Application->ShowHint = true;
		// to ensure assigning new HintWindow Class defined in HintWindow.cpp 


	// randomize
	TVPInitRandomGenerator();

	// memory usage
	{
		MEMORYSTATUS status;
		status.dwLength = sizeof(status);
		GlobalMemoryStatus(&status);

		TVPPushEnvironNoise(&status, sizeof(status));

		TVPTotalPhysMemory = status.dwTotalPhys;

		TVPAddImportantLog(TJS_W("(info) Total physical memory : ") +
			ttstr((int)TVPTotalPhysMemory) );

		tTJSVariant opt;
		if(TVPGetCommandLine(TJS_W("-memusage"), &opt))
		{
			ttstr str(opt);
			if(str == TJS_W("low"))
				TVPTotalPhysMemory = 0; // assumes zero
		}

		if(TVPTotalPhysMemory <= 36*1024*1024)
		{
			// very very low memory, forcing to assume zero memory
			TVPTotalPhysMemory = 0;
		}

		if(TVPTotalPhysMemory < 48*1024*1024)
		{
			// extra low memory
			if(TJSObjectHashBitsLimit > 0)
				TJSObjectHashBitsLimit = 0;
			TVPSegmentCacheLimit = 0;
			TVPFreeUnusedLayerCache = true; // in LayerIntf.cpp
		}
		else if(TVPTotalPhysMemory < 64*1024*1024)
		{
			// low memory
			if(TJSObjectHashBitsLimit > 4)
				TJSObjectHashBitsLimit = 4;
		}
	}


	char buf[MAX_PATH];
	bool bufset = false;
	bool nosel = false;
	bool forcesel = false;

	bool forcedataxp3 = GetSystemSecurityOption("forcedataxp3") != 0;
	bool acceptfilenameargument = GetSystemSecurityOption("acceptfilenameargument") != 0;

	if(!forcedataxp3 && !acceptfilenameargument)
	{
		if(TVPGetCommandLine(TJS_W("-nosel")) || TVPGetCommandLine(TJS_W("-about")))
		{
			nosel = true;
		}
		else
		{
			for(tjs_int i = 1; i<_argc; i++)
			{
				if(_argv[i][0] == '-' &&
					_argv[i][1] == '-' && _argv[i][2] == 0)
					break;

				if(_argv[i][0] != '-')
				{
					// TODO: set the current directory
					strncpy(buf, _argv[i], MAX_PATH-1);
					buf[MAX_PATH-1] = '\0';
					if(DirectoryExists(buf)) // is directory?
						strcat(buf, "\\");

					TVPProjectDirSelected = true;
					bufset = true;
					nosel = true;
				}
			}
		}
	}

	// check "-sel" option, to force show folder selection window
	if(!forcedataxp3 && TVPGetCommandLine(TJS_W("-sel")))
	{
		// sel option was set
		if(bufset)
		{
			char path[MAX_PATH];
			char *dum = 0;
			GetFullPathName(buf, MAX_PATH-1, path, &dum);
			strcpy(buf, path);
			TVPProjectDirSelected = false;
			bufset = true;
		}
		nosel = true;
		forcesel = true;
	}

	// check "content-data" directory
	if(!forcedataxp3 && !nosel)
	{
		char tmp[MAX_PATH];
		strcpy(tmp, IncludeTrailingBackslash(ExtractFileDir(ParamStr(0))).c_str());
		strcat(tmp, "content-data");
		if(DirectoryExists(tmp))
		{
			strcat(tmp, "\\");
			strcpy(buf, tmp);
			TVPProjectDirSelected = true;
			bufset = true;
			nosel = true;
		}
	}

	// check "data.xp3" archive
 	if(!nosel)
	{
		char tmp[MAX_PATH];
		strcpy(tmp, IncludeTrailingBackslash(ExtractFileDir(ParamStr(0))).c_str());
		strcat(tmp, "data.xp3");
		if(FileExists(tmp))
		{
			strcpy(buf, tmp);
			TVPProjectDirSelected = true;
			bufset = true;
			nosel = true;
		}
	}

	// check "data.exe" archive
 	if(!nosel)
	{
		char tmp[MAX_PATH];
		strcpy(tmp, IncludeTrailingBackslash(ExtractFileDir(ParamStr(0))).c_str());
		strcat(tmp, "data.exe");
		if(FileExists(tmp))
		{
			strcpy(buf, tmp);
			TVPProjectDirSelected = true;
			bufset = true;
			nosel = true;
		}
	}

	// check self combined xpk archive
	if(!nosel)
	{
		if(TVPIsXP3Archive(TVPNormalizeStorageName(ParamStr(0))))
		{
			strcpy(buf, ParamStr(0).c_str());
			TVPProjectDirSelected = true;
			bufset = true;
			nosel = true;
		}
	}


	// check "data" directory
	if(!forcedataxp3 && !nosel)
	{
		char tmp[MAX_PATH];
		strcpy(tmp, IncludeTrailingBackslash(ExtractFileDir(ParamStr(0))).c_str());
		strcat(tmp, "data");
		if(DirectoryExists(tmp))
		{
			strcat(tmp, "\\");
			strcpy(buf, tmp);
			TVPProjectDirSelected = true;
			bufset = true;
			nosel = true;
		}
	}

	// decide a directory to execute or to show folder selection
	if(!bufset)
	{
		if(forcedataxp3) throw EAbort("Aborted");
		strcpy(buf, ExtractFileDir(ParamStr(0)).c_str());
		int curdirlen = strlen(buf);
		if(buf[curdirlen-1] != '\\') buf[curdirlen] = '\\', buf[curdirlen+1] = 0;
	}

	if(!forcedataxp3 && (!nosel || forcesel))
	{
		// load krdevui.dll ( TVP[KiRikiri] Development User Interface )
		HMODULE krdevui = LoadLibrary("krdevui.dll");
		if(!krdevui)
		{
			AnsiString toolspath = (IncludeTrailingBackslash(
					ExtractFilePath(ParamStr(0))) + "tools\\krdevui.dll");
			krdevui = LoadLibrary(toolspath.c_str());
		}

		if(!krdevui)
		{
			// cannot locate the dll
			throw Exception(
				ttstr(TVPCannnotLocateUIDLLForFolderSelection).AsAnsiString());
		}

		typedef int PASCAL (*UIShowFolderSelectorForm_t)(void *reserved, char *buf);
		typedef void PASCAL (*UIGetVersion_t)(DWORD *hi, DWORD *low);

		UIShowFolderSelectorForm_t	UIShowFolderSelectorForm;
		UIGetVersion_t				UIGetVersion;

		UIShowFolderSelectorForm =
			(UIShowFolderSelectorForm_t)GetProcAddress(krdevui, "UIShowFolderSelectorForm");
		UIGetVersion =
			(UIGetVersion_t)GetProcAddress(krdevui, "UIGetVersion");

		if(!UIShowFolderSelectorForm || !UIGetVersion)
		{
			FreeLibrary(krdevui);
			throw Exception(ttstr(TVPInvalidUIDLL).AsAnsiString());
		}

		DWORD h, l;
		UIGetVersion(&h, &l);
		if(h != TVP_NEED_UI_VERSION)
		{
			FreeLibrary(krdevui);
			throw Exception(ttstr(TVPInvalidUIDLL).AsAnsiString());
		}


		int result = UIShowFolderSelectorForm(Application->Handle, buf);

//		FreeLibrary(krdevui);
		// FIXME: the library should be freed as soon as finishing to use it.

		if(result == mrAbort)
		{
			// display the main window
		}
		else
		if(result == mrCancel)
		{
			// cancel
			throw EAbort("Canceled");
		}
		else
		if(result == mrOk)
		{
			// ok, prepare to execute the script
			TVPProjectDirSelected = true;
		}
	}

	// check project dir and store some environmental variables
	if(TVPProjectDirSelected)
	{
		Application->ShowMainForm=false;
	}

	tjs_int buflen = strlen(buf);
	if(buflen >= 1)
	{
		if(buf[buflen-1] != '\\') buf[buflen] = TVPArchiveDelimiter, buf[buflen+1] = 0;
	}

	TVPProjectDir = TVPNormalizeStorageName(buf);
	TVPSetCurrentDirectory(TVPProjectDir);
	TVPNativeProjectDir = buf;

	if(TVPProjectDirSelected)
	{
		TVPAddImportantLog(TJS_W("(info) Selected project directory : ") +
			TVPProjectDir);
	}
}
const char *CTranscription::Tengwar2Roman(const char *str)
{
  string temp, cislo;
  static string res;
  unsigned int i, j;
  int hash;
  const char *p, *pend, *pp;
  //  const char *p2;
  char next;
  string prev;
  bool letterfound;
#ifdef DEBUG
  int tstart, tstop;
#endif
  string testentry;

#ifdef SPY
  printf("CTranscription::Tengwar2Roman\n");
#endif
  size_t len=strlen(str);
#ifdef DEBUG
  tstart=time(NULL);
#endif
  p=str;
/*R2T only
  p2:=AllocMem(Length(p));
  origp2:=p2;
  if(p2<>nil)then
    StrCopy(p2,p);
*/
  res="";
  prev=NON_ALPHA_NUM;
/*R2T
  if not Mode.casesens then
    p:=PChar(AnsiLowerCase(p));
*/
  pend=p+len;
  while(p<pend)
  {
    temp="";
    //bile znaky zkopirujeme beze zmeny
    while(Ord(p[0])<=32)
    {
      res+=p[0];
      prev=NON_ALPHA_NUM;
      p++;
     // p2++;
    }
    if(p>=pend)
      break;
    //predelani cisel
    if(TreatNumbersSeparately)
    {
      pp=p;
      cislo="";
      while((((pp[0]=='%')||(pp[0]=='T')||(pp[0]=='G')||(pp[0]=='B')||
              ((Ord(pp[0])>=152)&&(Ord(pp[0])<=153))||
              ((Ord(pp[0])>=168)&&(Ord(pp[0])<=169))||
              ((Ord(pp[0])>=200)&&(Ord(pp[0])<=203))
//            )&&(Ord(prev)>=240)&&(Ord(prev)<=251))||
             )&&(Ord(prev[prev.size()])>=240)&&(Ord(prev[prev.size()])<=251))||
            ((Ord(pp[0])>=240)&&(Ord(pp[0])<=251)))
      {
        cislo+=pp[0];
        prev=pp[0];
        pp++;
      }
      long l=pp-p;
      p+=l;
      //p2+=l;
      if(cislo!="")
      {
        for(long j=cislo.size();j>=1;j--)
          temp+=GetRomanDigit(cislo[j]);
        if(!decimal)
          temp=duodec2dec(temp);
        res+=temp;
#ifdef KYLIX
        Application.ProcessMessages();
#endif
        if(stop)
          throw EAbort("");
        continue;
      }
    }
    letterfound=false;
    hash=TengHash(p[0]);//Ord(p[0]);
    for(i=0;i<mode.t2r.src[hash]->count();i++)
    {
      size_t entrylen=(*mode.t2r.src[hash])[i].size();
      testentry="";
      for(j=0;j<entrylen;j++)
        testentry+=p[j];
      if(SmartCompare((*mode.t2r.src[hash])[i],testentry))
      {
        size_t l=(*mode.t2r.src[hash])[i].size();
        if((*mode.t2r.next[hash])[i]!="")
        {
          next=(*mode.t2r.next[hash])[i][0];
          if((*mode.t2r.next[hash])[i][0]==NON_ALPHA_NUM)
          {
            if((p+l<pend)&&(IsTengAlphaNum((p+l)[0])))
              continue;
          }
          else if((p+l>=pend)||((p+l)[0]!=next))
            continue;
        }
        if((*mode.t2r.prev[hash])[i]!="")
        {
          if(((*mode.t2r.prev[hash])[i][0]==NON_ALPHA_NUM)&&(IsTengAlphaNum(prev[prev.size()])))
            continue;
          else if((*mode.t2r.prev[hash])[i]!=prev)
            continue;
        }
        temp=(*mode.t2r.dest[hash])[i];
        letterfound=true;
        if((*mode.t2r.id[hash])[i].size()>0)
//          prev:=Mode.t2r.ID[hash][i][1]//Mode.tengwar[i][Length(Mode.tengwar[i])]
          prev=(*mode.t2r.id[hash])[i];
        else
          prev=NON_ALPHA_NUM;
        p+=l;
        //p2+=l;
        break;
      }
    }
      if(!letterfound) {
          if(alert)
          {
            for(i=0;!IsWhiteChar(p[i]);i++);
            throw EPatternNotFound(string(p).substr(0,i).c_str());
          }
          else
          {
            temp="?";
            p++;
           // p2++;
          }
      }
    res+=temp;
#ifdef KYLIX
    Application.ProcessMessages();
#endif    
    if(stop)
      throw EAbort("");
  }//while
//  showmessage(res);
/*R2T
  FreeMem(origp2);
*/
#ifdef DEBUG
  tstop=time(NULL);
  fprintf(stderr,"%d bytes: %d ms\n",len,tstop-tstart);
#endif

  return res.c_str();
}
const char *CTranscription::Roman2Tengwar(const char *str)
{
	string temp, cislo;
	static string res;
	unsigned int i;
	int hash;
	const char *p, *p2, *pend, *pp;
	char prev, next;
	bool letterfound;
#ifdef DEBUG
	int tstart, tstop;
#endif
	string testentry, str2;
	
#ifdef SPY
	fprintf(stderr,"CTranscription::Roman2Tengwar\n");
#endif
	p2=str;
	size_t len=strlen(str);
#ifdef DEBUG
	tstart=time(NULL);
#endif
	res="";
	prev=NON_ALPHA_NUM;
	if(!mode.casesens)
	{
		str2=lowercase(str);
		p=str2.c_str();
	}
	else
		p=p2;
	pend=p+len;
	while(p<pend)
	{
		temp="";
		//bile znaky zkopirujeme beze zmeny
		while(Ord(p[0])<=32)
		{
			res+=p[0];
			prev=NON_ALPHA_NUM;
			p++;
			p2++;
			if(p>=pend)
				break;
		}
		if(p>=pend)
			break;
		//predelani cisel
		if(TreatNumbersSeparately)
		{
			pp=p;
			cislo="";
			while((Ord(pp[0])>=Ord('0'))&&(Ord(pp[0])<=Ord('9')))
			{
				cislo+=pp[0];
				pp++;
			}
			long l=pp-p;
			p+=l;
			p2+=l;
			if(cislo!="")
			{
				if(!decimal)
					cislo=dec2duodec(cislo);
				for(long j=cislo.size()-1;j>=0;j--)
				{
					temp+=GetTengwarDigit(cislo[j]);
					if((lsd)&&(j==cislo.size()-1))//least sign. digit
					{
						if((cislo[j]=='0')||(cislo[j]=='4')||(cislo[j]=='7')||(cislo[j]=='8')||(cislo[j]=='a')||(cislo[j]=='b'))
							temp+='\x99';//153
						else
							temp+='\x98';//152
					}
					else if(digits)
					{
						if(decimal)
						{
							if((cislo[j]=='0')||(cislo[j]=='1')||(cislo[j]=='7')||(cislo[j]=='9'))
								temp+='T';
							else if((cislo[j]=='4')||(cislo[j]=='8'))
								temp+='G';
							else//2,3,5,6
								temp+='%';
						}
						else//duodecimal
						{
							if((cislo[j]=='3')||(cislo[j]=='5')||(cislo[j]=='6')||(cislo[j]=='9'))
								temp+='\xc8';//200
							else//0,1,2,4,7,8,10,11
								temp+='\xc9';//201
						}
					}//if digits
				}
				res+=temp;
#ifdef KYLIX
				Application.ProcessMessages();
#endif
				if(stop)
					throw EAbort("");
				continue;
			}//if cislo
		}//if tns
		letterfound=false;
		hash=Ord(p[0]);
		for(i=0;i<mode.r2t.src[hash]->count();i++)
		{
			size_t entrylen=(*mode.r2t.src[hash])[i].size();
			testentry="";
			for(size_t j=0;j<entrylen;j++)
				testentry+=p[j];
			if((*mode.r2t.src[hash])[i]==testentry)
			{
				size_t l=(*mode.r2t.src[hash])[i].size();
				if((*mode.r2t.next[hash])[i]!="")
				{
					next=(*mode.r2t.next[hash])[i][0];
					if((*mode.r2t.next[hash])[i][0]==NON_ALPHA_NUM)
					{
						if((p+l<pend)&&(isalnum((p+l)[0])))
							continue;
					}
					else if((p+l>=pend)||((p+l)[0]!=next))
						continue;
				}
				if((*mode.r2t.prev[hash])[i]!="")
				{
					if(((*mode.r2t.prev[hash])[i][0]==NON_ALPHA_NUM)&&(isalnum(prev)))
						continue;
					else if((*mode.r2t.prev[hash])[i][0]!=prev)
						continue;
				}
				temp=(*mode.r2t.dest[hash])[i];
				letterfound=true;
				if((*mode.r2t.id[hash])[i].size()>0)
					prev=(*mode.r2t.id[hash])[i][0];
				else
					prev=NON_ALPHA_NUM;
				p+=l;
				p2+=l;
				break;
			}
		}
        if(!letterfound) {
			if(alert)
			{
				for(i=0;!IsWhiteChar(p[i]);i++);
				throw EPatternNotFound(string(p2).substr(0,i).c_str());
			}
            else
            {
                temp='\xae';//'?'
                p++;
                p2++;
            }
        }
        res+=temp;
#ifdef KYLIX
		Application.ProcessMessages();
#endif
		if(stop)
			throw EAbort("");
	}
	
#ifdef DEBUG
	tstop=time(NULL);
	fprintf(stderr,"%d bytes: %d ms\n",len,tstop-tstart);
#endif
	
	return res.c_str();
}