Example #1
0
bool ProcessInstance::CanExecuteOn( const ImageVariant& image, String& whyNot ) const
{
   if ( !image.IsSharedImage() || !image.IsCompletelySelected() )
   {
      ImageVariant tmp;
      tmp.CreateSharedImageAs( image ).AssignImage( image );
      return CanExecuteOn( tmp, whyNot );
   }

   image.PushSelections();
   image.ResetSelections();

   ImageInfo info1( *image );

   image.PopSelections();

   whyNot.Clear();
   whyNot.Reserve( WHYNOT_MAXLENGTH );

   bool ok = (*API->Process->ValidateImageExecution)( handle, image.SharedImageHandle(), whyNot.c_str(), WHYNOT_MAXLENGTH ) != api_false;

   image.PushSelections();
   image.ResetSelections();

   ImageInfo info2( *image );

   image.PopSelections();

   if ( info1 != info2 )
      APIHackingAttempt( "ValidateImageExecution" );

   return ok;
}
Example #2
0
String ProcessInstance::Description() const
{
   size_type len = 0;
   (*API->Process->GetProcessInstanceDescription)( handle, 0, &len );

   String description;

   if ( len != 0 )
   {
      description.Reserve( len );
      if ( (*API->Process->GetProcessInstanceDescription)( handle, description.c_str(), &len ) == api_false )
         throw APIFunctionError( "GetProcessInstanceDescription" );
   }

   return description;
}
Example #3
0
String Label::Text() const
{
   size_type len = 0;
   (*API->Label->GetLabelText)( handle, 0, &len );

   String text;

   if ( len != 0 )
   {
      text.Reserve( len );

      if ( (*API->Label->GetLabelText)( handle, text.c_str(), &len ) == api_false )
         throw APIFunctionError( "GetLabelText" );
   }

   return text;
}
Example #4
0
bool OpenFileDialog::Execute()
{
   q->fileNames.Clear();

   String apiFilters = p->MakeAPIFilters();

   String fileName;
   fileName.Reserve( 8192 );
   *fileName.c_str() = CharTraits::Null();

   if ( q->multipleSelections )
   {
      if ( (*API->Dialog->ExecuteOpenMultipleFilesDialog)( fileName.c_str(),
               AddFileNameToList, &q->fileNames,
               p->caption.c_str(),
               p->initialPath.c_str(), apiFilters.c_str(), p->fileExtension.c_str() ) == api_false )
      {
         return false;
      }
   }
   else
   {
      if ( (*API->Dialog->ExecuteOpenFileDialog)( fileName.c_str(),
               p->caption.c_str(),
               p->initialPath.c_str(), apiFilters.c_str(), p->fileExtension.c_str() ) == api_false )
      {
         return false;
      }

      fileName.ResizeToNullTerminated();
      if ( !fileName.IsEmpty() )
         q->fileNames.Add( fileName );
   }

   if ( !q->fileNames.IsEmpty() )
   {
      p->fileExtension = File::ExtractExtension( *q->fileNames );
      return true;
   }

   return false;
}
Example #5
0
Variant ProcessInstance::ParameterValue( const ProcessParameter& parameter, size_type rowIndex ) const
{
   if ( parameter.IsNull() )
      return Variant();

   // First call to get the parameter type and length
   uint32 apiType = 0;
   size_type len = 0;
   (*API->Process->GetParameterValue)( handle, parameter.Handle(), rowIndex, &apiType, 0, &len );
   apiType &= PTYPE_TYPE_MASK;
   if ( apiType == 0 )
      throw APIFunctionError( "GetParameterValue" );

   if ( apiType == PTYPE_TABLE )
      throw Error( "ProcessInstance::ParameterValue(): Invoked for a table parameter" );

   if ( apiType == PTYPE_STRING )
   {
      String value;
      if ( len > 0 )
      {
         value.Reserve( len );
         if ( (*API->Process->GetParameterValue)( handle, parameter.Handle(),
                                                  rowIndex, &apiType, value.c_str(), &len ) == api_false )
            throw APIFunctionError( "GetParameterValue" );
      }
      return value;
   }

   if ( apiType == PTYPE_BLOCK )
   {
      ByteArray value( len );
      if ( len > 0 )
      {
         if ( (*API->Process->GetParameterValue)( handle, parameter.Handle(),
                                                  rowIndex, &apiType, value.Begin(), &len ) == api_false )
            throw APIFunctionError( "GetParameterValue" );
      }
      return value;
   }

   union
   {
      uint8    u8;
      int8     i8;
      uint16   u16;
      int16    i16;
      uint32   u32;
      int32    i32;
      uint64   u64;
      int64    i64;
      float    f;
      double   d;
      api_bool b;
      api_enum e;
   }
   value;

   if ( (*API->Process->GetParameterValue)( handle, parameter.Handle(),
                                            rowIndex, &apiType, &value, 0 ) == api_false )
      throw APIFunctionError( "GetParameterValue" );

   switch ( apiType )
   {
   case PTYPE_UINT8:  return value.u8;
   case PTYPE_INT8:   return value.i8;
   case PTYPE_UINT16: return value.u16;
   case PTYPE_INT16:  return value.i16;
   case PTYPE_UINT32: return value.u32;
   case PTYPE_INT32:  return value.i32;
   case PTYPE_UINT64: return value.u64;
   case PTYPE_INT64:  return value.i64;
   case PTYPE_FLOAT:  return value.f;
   case PTYPE_DOUBLE: return value.d;
   case PTYPE_BOOL:   return value.b;
   case PTYPE_ENUM:   return value.e;
   default:
      throw Error( "ProcessParameter::ParameterValue(): Internal error: Unknown parameter type" );
   }
}
Example #6
0
bool ProcessInstance::CanExecuteGlobal( String& whyNot ) const
{
   whyNot.Clear();
   whyNot.Reserve( WHYNOT_MAXLENGTH );
   return (*API->Process->ValidateGlobalExecution)( handle, whyNot.c_str(), WHYNOT_MAXLENGTH ) != api_false;
}
Example #7
0
bool ProcessInstance::Validate( String& whyNot )
{
   whyNot.Clear();
   whyNot.Reserve( WHYNOT_MAXLENGTH );
   return (*API->Process->ValidateProcessInstance)( handle, whyNot.c_str(), WHYNOT_MAXLENGTH ) != api_false;
}
Example #8
0
void Lex::Next()
{
	grounding = false;
	while((byte)*ptr <= ' ') {
		if(*ptr == '\2')
			grounding = true;
		if(*ptr == '\0') return;
		ptr++;
	}
	pos = ptr;
	int c = (byte)*ptr++;
	if(c == '\0') return;
	switch(c) {
	case_id: {
			String x;
			x.Reserve(12);
			x.Cat(c);
			while(iscid(*ptr))
				x.Cat(*ptr++);
			int q = id.FindAdd(x);
			if(q == tk_rval_ - 256) { // simple hack for transitionary macro
				AddCode('&');
				AddCode('&');
			}
			else
				AddCode(q + 256);
			break;
		}
	case ':': AddCode(Char(':') ? t_dblcolon : ':'); break;
	case '*': AssOp('*', t_mulass); break;
	case '/': AssOp('/', t_divass); break;
	case '%': AssOp('%', t_modass); break;
	case '^': AssOp('^', t_xorass); break;
	case '!': AssOp('!', t_neq); break;
	case '.':
		if(Char('*')) AddCode(t_dot_asteriks);
		else
		if(*ptr == '.' && ptr[1] == '.') {
			AddCode(t_elipsis);
			ptr += 2;
		}
		else
			AddCode('.');
		break;
	case '+':
		if(Char('+')) AddCode(t_inc);
		else
			AssOp('+', t_addass);
		return;
	case '-':
		if(Char('-')) AddCode(t_dec);
		else
		if(Char('>'))
			AddCode(Char('*') ? t_arrow_asteriks : t_arrow);
		else
			AssOp('-', t_subass);
		break;
	case '&':
		if(Char('&'))
			AddCode(t_and);
		else
			AssOp('&', t_andass);
		break;
	case '|':
		if(Char('|'))
			AddCode(t_or);
		else
			AssOp('|', t_orass);
		break;
	case '=':
		AssOp('=', t_eq);
		break;
	case '<':
		if(Char('<'))
			AssOp(t_shl, t_shlass);
		else
			AssOp('<', t_le);
		break;
	case '>':
		if(Char('>'))
			AssOp(t_shr, t_shrass);
		else
			AssOp('>', t_ge);
		break;
	case '0': {
			dword w = 0;
			if(Char('x') || Char('X')) {
				for(;;) {
					int d;
					if(*ptr >= '0' && *ptr <= '9')
						d = *ptr - '0';
					else
					if(*ptr >= 'A' && *ptr <= 'F')
						d = *ptr - 'A' + 10;
					else
					if(*ptr >= 'a' && *ptr <= 'f')
						d = *ptr - 'a' + 10;
					else
						break;
					if(w >= 0x8000000u - d) {
						AddCode(te_integeroverflow);
						return;
					}
					w = w * 16 + d - '0';
					ptr++;
				}
			}
			else
				while(*ptr >= '0' && *ptr <= '7') {
					int d = *ptr++ - '0';
					if(w >= 0x1000000u - d) {
						AddCode(te_integeroverflow);
						return;
					}
					w = w * 8 + d - '0';
				}
			Term& tm = term.AddTail();
			tm.code = t_integer;
			tm.ptr = pos;
			tm.number = w;
		}
		break;
	case_nonzero_digit: {
			double w = c - '0';
			bool fp = false;
			while(*ptr >= '0' && *ptr <= '9')
				w = w * 10 + *ptr++ - '0';
			if(*ptr == '.') { //TODO TO BE Completed !!!
				fp = true;
				ptr++;
				double x = 0.1;
				while(*ptr >= '0' && *ptr <= '9') {
					w += x * (*ptr++ - '0');
					x /= 10;
				}
			}
			Term& tm = term.AddTail();
			if(fp || w < INT_MIN || w > INT_MAX)
				tm.code = t_double;
			else
				tm.code = t_integer;
			tm.ptr = pos;
			tm.number = w;
		}
		break;
	case '\'': {
			Term& tm = term.AddTail();
			tm.code = t_character;
			tm.ptr = pos;
			tm.text = String(GetCharacter(), 1);
			if(*ptr == '\'')
				ptr++;
			else
				tm.code = te_badcharacter;
		}
		break;
	case '\"': {
			Term& tm = term.AddTail();
			tm.code = t_string;
			tm.ptr = pos;
			for(;;) {
				while(*ptr != '\"') {
					if((byte)*ptr < ' ' && *ptr != 9) {
						tm.code = te_badstring;
						return;
					}
					tm.text.Cat(GetCharacter());
				}
				ptr++;
				while(*ptr && (byte)*ptr <= ' ') ptr++;
				if(*ptr != '\"') break;
				ptr++;
			}
		}
		break;
	default:
		AddCode(c);
		return;
	}
}
	bool PluginManager::Mount(const String& pluginPath, bool appendExtension)
	{
		if (!Initialize())
		{
			NazaraError("Failed to initialize PluginManager");
			return false;
		}

		String path = pluginPath;
		if (appendExtension && !path.EndsWith(NAZARA_DYNLIB_EXTENSION))
			path += NAZARA_DYNLIB_EXTENSION;

		bool exists = false;
		if (!File::IsAbsolute(path))
		{
			for (const String& dir : s_directories)
			{
				String testPath;
				testPath.Reserve(dir.GetSize() + path.GetSize() + 10);

				testPath = dir;
				testPath += NAZARA_DIRECTORY_SEPARATOR;
				testPath += path;

				if (File::Exists(testPath))
				{
					path = testPath;
					exists = true;
					break;
				}
			}
		}
		else if (File::Exists(path))
			exists = true;

		if (!exists)
		{
			NazaraError("Failed to find plugin file");
			return false;
		}

		std::unique_ptr<DynLib> library(new DynLib);
		if (!library->Load(path))
		{
			NazaraError("Failed to load plugin");
			return false;
		}

		PluginLoad func = reinterpret_cast<PluginLoad>(library->GetSymbol("PluginLoad"));
		if (!func)
		{
			NazaraError("Failed to get symbol PluginLoad");
			return false;
		}

		if (!func())
		{
			NazaraError("Plugin failed to load");
			return false;
		}

		s_plugins[pluginPath] = library.release();

		return true;
	}