int DownloadDialog::ExecOnThread()
{
    if (IsRequired())
    {
        try
        {
            for (size_t i = 0; i < downloadfiles.size(); i++)
            {
                if (callback && callback->IsDownloadCancelled())
                {
                    return -2;
                }

                downloadfiles[i]->Exec(callback);
            }

            if (callback)
            {
                callback->DownloadComplete();
            }
        }
        catch(std::exception& ex)
        {
            if (callback)
            {
                callback->DownloadError(DVLib::string2wstring(ex.what()).c_str());
            }

            throw;
        }
    }

    return 0;
}
JBoolean
JXRegexReplaceInput::InputValid()
{
	if (!JXInputField::InputValid())
		{
		return kJFalse;
		}
	else
		{
		const JString& text = GetText();

		if (!IsRequired() && text.IsEmpty())
			{
			return kJTrue;
			}

		const JError err = itsTestRegex->SetReplacePattern(text);
		if (err.OK())
			{
			return kJTrue;
			}
		else
			{
			err.ReportIfError();
			return kJFalse;
			}
		}
}
Exemple #3
0
StringRef SirenFieldAttribute::Modifier() const
{
	if (IsRequired())
	{
		return "Required";
	}
	return "Optional";
}
JBoolean
JXFileInput::InputValid()
{
	if (itsAllowInvalidFileFlag)
		{
		return kJTrue;
		}
	else if (!JXInputField::InputValid())
		{
		return kJFalse;
		}

	const JString& text = GetText();
	if (text.IsEmpty())
		{
		return JNegate(IsRequired());
		}

	JString fullName;
	const JCharacter* errID = NULL;
	if (JIsRelativePath(text) && !HasBasePath())
		{
		errID = kNoRelPathID;
		RecalcAll(kJTrue);
		}
	else if (!JConvertToAbsolutePath(text, itsBasePath, &fullName) ||
			 !JFileExists(fullName))
		{
		errID = kDoesNotExistID;
		}
	else if (itsRequireReadFlag && !JFileReadable(fullName))
		{
		errID = kUnreadableID;
		}
	else if (itsRequireWriteFlag && !JFileWritable(fullName))
		{
		errID = kUnwritableID;
		}
	else if (itsRequireExecFlag && !JFileExecutable(fullName))
		{
		errID = kCannotExecID;
		}

	if (JStringEmpty(errID))
		{
		return kJTrue;
		}
	else
		{
		(JGetUserNotification())->ReportError(JGetString(errID));
		return kJFalse;
		}
}
JBoolean
JXPathInput::InputValid()
{
	if (itsAllowInvalidPathFlag)
		{
		return kJTrue;
		}
	else if (!JXInputField::InputValid())
		{
		return kJFalse;
		}

	const JString& text = GetText();
	if (text.IsEmpty())		// paranoia -- JXInputField should have reported
		{
		return !IsRequired();
		}

	JString path;
	if (JIsRelativePath(text) && !HasBasePath())
		{
		(JGetUserNotification())->ReportError(JGetString(kNoRelPathID));
		RecalcAll(kJTrue);
		return kJFalse;
		}
	if (!JConvertToAbsolutePath(text, itsBasePath, &path))
		{
		(JGetUserNotification())->ReportError(JGetString(kInvalidPathID));
		RecalcAll(kJTrue);
		return kJFalse;
		}

	const JString currDir = JGetCurrentDirectory();
	const JError err      = JChangeDirectory(path);
	JChangeDirectory(currDir);

	if (err.OK())
		{
		if (!JDirectoryReadable(path))
			{
			(JGetUserNotification())->ReportError(JGetString(kUnreadableID));
			RecalcAll(kJTrue);
			return kJFalse;
			}
		else if (itsRequireWriteFlag && !JDirectoryWritable(path))
			{
			(JGetUserNotification())->ReportError(JGetString(kUnwritableID));
			RecalcAll(kJTrue);
			return kJFalse;
			}
		else
			{
			return kJTrue;
			}
		}

	const JCharacter* errID;
	if (err == kJAccessDenied)
		{
		errID = kAccessDeniedID;
		}
	else if (err == kJBadPath)
		{
		errID = kBadPathID;
		}
	else if (err == kJComponentNotDirectory)
		{
		errID = kCompNotDirID;
		}
	else
		{
		errID = kInvalidDirID;
		}

	(JGetUserNotification())->ReportError(JGetString(errID));
	RecalcAll(kJTrue);
	return kJFalse;
}
JBoolean
JXFloatInput::InputValid()
{
	if (!JXInputField::InputValid())
		{
		return kJFalse;
		}
	else
		{
		const JString& text = GetText();

		if (!IsRequired() && text.IsEmpty())
			{
			return kJTrue;
			}

		JFloat value;
		if (!text.ConvertToFloat(&value))
			{
			(JGetUserNotification())->ReportError(JGetString(kNotANumberID));
			return kJFalse;
			}

		const JBoolean valid = ValueValid(value);
		JString errorStr;
		if (!valid && itsHasLowerLimitFlag && itsHasUpperLimitFlag)
			{
			const JString n(itsLowerLimit), m(itsUpperLimit);
			const JCharacter* map[] =
				{
				"min", n.GetCString(),
				"max", m.GetCString()
				};
			errorStr = JGetString(kOutsideRangeID, map, sizeof(map));
			}
		else if (!valid && itsHasLowerLimitFlag)
			{
			const JString n(itsLowerLimit);
			const JCharacter* map[] =
				{
				"min", n.GetCString()
				};
			errorStr = JGetString(kBelowMinID, map, sizeof(map));
			}
		else if (!valid)
			{
			assert( itsHasUpperLimitFlag );

			const JString n(itsUpperLimit);
			const JCharacter* map[] =
				{
				"max", n.GetCString()
				};
			errorStr = JGetString(kAboveMaxID, map, sizeof(map));
			}

		if (!valid)
			{
			(JGetUserNotification())->ReportError(errorStr);
			}
		return valid;
		}
}