bool FSCopyFile(const unicode_t *srcFileName, const unicode_t *desFileName, bool bFailIfExists/* = true*/)
{
#if defined(_WIN32_WCE)
	return 	CopyFile(srcFileName, desFileName, bFailIfExists) == TRUE;
#elif defined(WIN32)
	return 	CopyFileW(srcFileName, desFileName, bFailIfExists) == TRUE;
#elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
	FSString	srcString(srcFileName);
	FSString	desString(desFileName);
	
	if ( srcString == desString ) return false;
	
	if ( bFailIfExists )
	{
		if ( _ExistFile(desString.GetString()) ) return false;
	}
	
	return _CopyFile(srcFileName, desFileName);
	
//	return copyfile(srcString.GetString(), desString.GetString(), NULL, bFailIfExists ? COPYFILE_ALL | COPYFILE_EXCL : COPYFILE_ALL) == 0;
#else
	FSString	srcString(srcFileName);
	FSString	desString(desFileName);
	
	if ( srcString == desString ) return false;
	
	if ( bFailIfExists )
	{
		if ( _ExistFile(desString.GetString()) ) return false;
	}
	return copyfile(srcString.GetString(), desString.GetString(), NULL, bFailIfExists? COPYFILE_ALL | COPYFILE_EXCL : COPYFILE_ALL) == 0;
#endif
}
示例#2
0
/**
 * MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
 * MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
 * MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
 * MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
 * MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
 * MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
 * d174ab98d277d9f5a5611c2c9f419d9f
 * MD5 ("123456789012345678901234567890123456789012345678901234567890123456
 * 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
 */
void md5String(){
    const char *src = NULL;
    AS3_MallocString(src, input);

    std::string srcString(src);

    const char *result;

    hashwrapper *wrapper;

    wrapper = new md5wrapper();
    std::string md5 = wrapper->getHashFromString(srcString);

    result = md5.c_str();

    delete wrapper;

    // We can't just call AS3_Return(s) because s is not a scalar.
    // Instead we need to marshall the C string into AS3 and use
    // AS3_ReturnAS3Var().

    AS3_DeclareVar(myString, String);
    AS3_CopyCStringToVar(myString, result, 32);
    AS3_ReturnAS3Var(myString);
}
bool FSCopyFile(const char *srcFileName, const char *desFileName, bool bFailIfExists/* = true*/)
{
#if defined(_WIN32_WCE)
	return 	CopyFile(UniString(srcFileName), UniString(desFileName), bFailIfExists) == TRUE;
#elif defined(WIN32)
	return 	CopyFileA(srcFileName, desFileName, bFailIfExists) == TRUE;
#elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
	UniString	srcString(srcFileName);
	UniString	desString(desFileName);
	return FSCopyFile(srcString, desString);
#else
	UniString	srcString(srcFileName);
	UniString	desString(desFileName);
	return FSCopyFile(srcString, desString);
#endif
}
示例#4
0
nsresult
ImageDocument::CreateSyntheticDocument()
{
  // Synthesize an html document that refers to the image
  nsresult rv = MediaDocument::CreateSyntheticDocument();
  NS_ENSURE_SUCCESS(rv, rv);

  // Add the image element
  Element* body = GetBodyElement();
  if (!body) {
    NS_WARNING("no body on image document!");
    return NS_ERROR_FAILURE;
  }

  nsCOMPtr<nsINodeInfo> nodeInfo;
  nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::img, nullptr,
                                           kNameSpaceID_XHTML,
                                           nsIDOMNode::ELEMENT_NODE);

  mImageContent = NS_NewHTMLImageElement(nodeInfo.forget());
  if (!mImageContent) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
  NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);

  nsAutoCString src;
  mDocumentURI->GetSpec(src);

  NS_ConvertUTF8toUTF16 srcString(src);
  // Make sure not to start the image load from here...
  // imageLoader->SetLoadingEnabled(false);
  mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::src, srcString, false);
  mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::alt, srcString, false);

  //Pale Moon: implement mechanism for custom background color.

  if (!mBackgroundColor.IsEmpty()) {
    nsCSSValue color;
    nsCSSParser parser;
    if (parser.ParseColorString(mBackgroundColor, nullptr, 0, color)) {
      nsAutoString styleAttr(NS_LITERAL_STRING("background-color: "));
      styleAttr.Append(mBackgroundColor);
      body->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleAttr, false);
    }
  }

  body->AppendChildTo(mImageContent, false);
  // imageLoader->SetLoadingEnabled(true);

// PM
  UpdateTitleAndCharset();

  return NS_OK;
}
示例#5
0
nsresult
ImageDocument::CreateSyntheticDocument()
{
  // Synthesize an html document that refers to the image
  nsresult rv = MediaDocument::CreateSyntheticDocument();
  NS_ENSURE_SUCCESS(rv, rv);

  // Add the image element
  Element* body = GetBodyElement();
  if (!body) {
    NS_WARNING("no body on image document!");
    return NS_ERROR_FAILURE;
  }

  nsCOMPtr<nsINodeInfo> nodeInfo;
  nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::img, nullptr,
                                           kNameSpaceID_XHTML,
                                           nsIDOMNode::ELEMENT_NODE);

  mImageContent = NS_NewHTMLImageElement(nodeInfo.forget());
  if (!mImageContent) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageContent);
  NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);

  nsAutoCString src;
  mDocumentURI->GetSpec(src);

  // Push a null JSContext on the stack so that code that runs within
  // the below code doesn't think it's being called by JS. See bug
  // 604262.
  nsCxPusher pusher;
  pusher.PushNull();

  NS_ConvertUTF8toUTF16 srcString(src);
  // Make sure not to start the image load from here...
  imageLoader->SetLoadingEnabled(false);
  mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::src, srcString, false);
  mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::alt, srcString, false);

  body->AppendChildTo(mImageContent, false);
  imageLoader->SetLoadingEnabled(true);

  return NS_OK;
}
示例#6
0
nsresult
ImageDocument::OnLoadComplete(imgIRequest* aRequest, nsresult aStatus)
{
  UpdateTitleAndCharset();

  // mImageContent can be null if the document is already destroyed
  if (NS_FAILED(aStatus) && mStringBundle && mImageContent) {
    nsAutoCString src;
    mDocumentURI->GetSpec(src);
    NS_ConvertUTF8toUTF16 srcString(src);
    const char16_t* formatString[] = { srcString.get() };
    nsXPIDLString errorMsg;
    mStringBundle->FormatStringFromName(u"InvalidImage", formatString, 1,
                                        getter_Copies(errorMsg));

    mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::alt, errorMsg, false);
  }

  return NS_OK;
}
示例#7
0
U_CAPI void U_EXPORT2
umsg_vparse(const UMessageFormat *fmt,
            const UChar    *source,
            int32_t        sourceLength,
            int32_t        *count,
            va_list        ap,
            UErrorCode     *status)
{
    //check arguments
    if(status==NULL||U_FAILURE(*status))
    {
        return;
    }
    if(fmt==NULL||source==NULL || sourceLength<-1 || count==NULL){
        *status=U_ILLEGAL_ARGUMENT_ERROR;
        return;
    }
    if(sourceLength==-1){
        sourceLength=u_strlen(source);
    }

    UnicodeString srcString(source,sourceLength);
    Formattable *args = ((const MessageFormat*)fmt)->parse(srcString,*count,*status);
    UDate *aDate;
    double *aDouble;
    UChar *aString;
    int32_t* aInt;
    int64_t* aInt64;
    UnicodeString temp;
    int len =0;
    // assign formattables to varargs
    for(int32_t i = 0; i < *count; i++) {
        switch(args[i].getType()) {

        case Formattable::kDate:
            aDate = va_arg(ap, UDate*);
            if(aDate){
                *aDate = args[i].getDate();
            }else{
                *status=U_ILLEGAL_ARGUMENT_ERROR;
            }
            break;

        case Formattable::kDouble:
            aDouble = va_arg(ap, double*);
            if(aDouble){
                *aDouble = args[i].getDouble();
            }else{
                *status=U_ILLEGAL_ARGUMENT_ERROR;
            }
            break;

        case Formattable::kLong:
            aInt = va_arg(ap, int32_t*);
            if(aInt){
                *aInt = (int32_t) args[i].getLong();
            }else{
                *status=U_ILLEGAL_ARGUMENT_ERROR;
            }
            break;

        case Formattable::kInt64:
            aInt64 = va_arg(ap, int64_t*);
            if(aInt64){
                *aInt64 = args[i].getInt64();
            }else{
                *status=U_ILLEGAL_ARGUMENT_ERROR;
            }
            break;

        case Formattable::kString:
            aString = va_arg(ap, UChar*);
            if(aString){
                args[i].getString(temp);
                len = temp.length();
                temp.extract(0,len,aString);
                aString[len]=0;
            }else{
                *status= U_ILLEGAL_ARGUMENT_ERROR;
            }
            break;

        case Formattable::kObject:
            // This will never happen because MessageFormat doesn't
            // support kObject.  When MessageFormat is changed to
            // understand MeasureFormats, modify this code to do the
            // right thing. [alan]
            U_ASSERT(FALSE);
            break;

        // better not happen!
        case Formattable::kArray:
            U_ASSERT(FALSE);
            break;
        }
    }

    // clean up
    delete [] args;
}
示例#8
0
GLuint GlProgram::loadShader(GLenum type, const GLchar* src){
	//LOGD("loadShader()");
	GLuint shaderHandle = glCreateShader(type);

	glShaderSource(shaderHandle, 1, &src, NULL);
	glCompileShader(shaderHandle);

	GLint compileStatus;
	glGetShaderiv(shaderHandle, GL_COMPILE_STATUS,&compileStatus);

	if(compileStatus == GL_FALSE) {
		glDeleteShader(shaderHandle);
		LOGE("Failed to compile %s",((type == GL_VERTEX_SHADER)? "vertex":"fragment"));
		return UNBIND_HANDLE;
	}

	//Parse shader to store attributes and uniform handles
	string srcString(src);
	size_t mainStart = srcString.find("void main()");
	bool goOn = true;
	size_t pos = 0;
	while(goOn){
		pos = srcString.find("attribute ", pos);
		if(pos < mainStart && pos != string::npos){
			int start = pos + 9;
			while(srcString.at(++start) == ' ');
			while(srcString.at(++start) != ' ');
			while(srcString.at(++start) == ' ');
			int stop = start;
			while(srcString.at(stop) != ' ' && srcString.at(stop) != ';') stop++;
			GLchar *attributeName = new GLchar[(stop-start)+1];
			srcString.copy(attributeName, stop-start,start);
			attributeName[stop-start] = '\0';
			if(this->attributeHandles.count(attributeName) == 0){
				this->attributeHandles[attributeName] = UNBIND_HANDLE;
			}
			pos = stop;
		}
		else{
			goOn = false;
		}
	}

	goOn = true;
	pos = 0;
	while(goOn){
		pos = srcString.find("uniform ", pos);
		if(pos < mainStart && pos != string::npos){
			int start = pos + 7;
			while(srcString.at(++start) == ' ');
			while(srcString.at(++start) != ' ');
			while(srcString.at(++start) == ' ');
			int stop = start;
			while(srcString.at(stop) != ' ' && srcString.at(stop) != ';') stop++;
			GLchar *uniformName = new GLchar[(stop-start)+1];
			srcString.copy(uniformName, stop-start,start);
			uniformName[stop-start] = '\0';
			if(this->uniformHandles.count(uniformName) == 0){
				this->uniformHandles[uniformName] = UNBIND_HANDLE;
			}
			pos = stop;
		}
		else{
			goOn = false;
		}
	}

	return shaderHandle;
}