ExamineObject()

This forum is for general developer support questions.
User avatar
Coder
Posts: 7
Joined: Sat Apr 21, 2012 12:56 pm
Location: The Netherlands
Contact:

ExamineObject()

Post by Coder »

Hi,

Am I correct in saying that now to get all the file info from a file you should use ExamineObject()?

Cheers,
Coder
User avatar
abalaban
Beta Tester
Beta Tester
Posts: 456
Joined: Mon Dec 20, 2010 2:09 pm
Location: France
Contact:

Re: ExamineObject()

Post by abalaban »

Coder wrote:Hi,
Am I correct in saying that now to get all the file info from a file you should use ExamineObject()?
Indeed you are right!
AmigaOne X1000 running AOS 4 beta
AmigaOne XE/G4
Amiga 1200/PPC 603e + BVision PPC
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1483
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: ExamineObject()

Post by tonyw »

You'll find it a hell of a lot easier than the old way. Faster, too.
cheers
tony
User avatar
Coder
Posts: 7
Joined: Sat Apr 21, 2012 12:56 pm
Location: The Netherlands
Contact:

Re: ExamineObject()

Post by Coder »

@abalaban/Tony

Thanks. I read the dos library autodoc and did notice some changes including the ExamineObject(). I have not seen any examples around on the net using the ExamineObject().

Cheers,
Coder
User avatar
abalaban
Beta Tester
Beta Tester
Posts: 456
Joined: Mon Dec 20, 2010 2:09 pm
Location: France
Contact:

Re: ExamineObject()

Post by abalaban »

Simplified example from my CompareDirs tool :

Code: Select all

	int32 success= FALSE;
	APTR context = IDOS->ObtainDirContextTags( EX_StringNameInput, dirname,
                                        EX_DoCurrentDir,TRUE, /* for recursive lock */
                                        EX_DataFields,(EXF_NAME|EXF_LINK|EXF_TYPE|EXF_SIZE|EXF_DATE),
                                        TAG_END);
	if (context)
	{
		struct ExamineData *dat;

		while ((dat = IDOS->ExamineDir(context)))
		{
			if ( EXD_IS_DIRECTORY(dat))
			{
				IDOS->PrintF("%s is a directory\n", dat->Name);
			}
			else
			{		
				int64 fileSize = dat->FileSize;
				if ( EXD_IS_LINK(dat) )
				{ // it's a link try to resolve it
					struct ExamineData * linkedobj=
									IDOS->ExamineObjectTags(EX_StringNameInput,dat->Link,TAG_END);
					if (linkedobj)
					{
						fileSize = linkedobj->FileSize;
						IDOS->PrintF("%s is a link to %s whose size is %lld\n", dat->Name, linkedobj->Name, fileSize);

						IDOS->FreeDosObject(DOS_EXAMINEDATA, linkedobj);
						linkedobj = NULL;
					}
				}
				else
				{
					IDOS->PrintF("%s is a file whose size is %lld\n", dat->Name, fileSize);					
				}
			}
		}

		if ( ERROR_NO_MORE_ENTRIES == IoErr())
		{
			success = TRUE; /* normal exit */
		}
		else
		{
			UI->error( _T(MSG_ERR_EXAMINING_DIR) ); /* failure - why ? */
		}

	}
	else
	{
		UI->error( _T(MSG_ERR_OBTAINING_DIR_CONTEXT) ); /* failure - why ? */
	}

	IDOS->ReleaseDirContext(context); /* NULL safe */
You have examples of both ExamineObject (to resolve the link) and ExamineDir, ask if you want more. I'll probably create an article in the wiki about this.
Last edited by abalaban on Tue Mar 12, 2013 12:11 pm, edited 1 time in total.
AmigaOne X1000 running AOS 4 beta
AmigaOne XE/G4
Amiga 1200/PPC 603e + BVision PPC
User avatar
cha05e90
Posts: 90
Joined: Fri Jun 17, 2011 11:15 pm
Location: Germany
Contact:

Re: ExamineObject()

Post by cha05e90 »

abalaban wrote:I'll probably create an article in the wiki about this.
Pretty, pretty please! :P
X1000|II/G4|440ep|2000/060|2000/040|1000
User avatar
Coder
Posts: 7
Joined: Sat Apr 21, 2012 12:56 pm
Location: The Netherlands
Contact:

Re: ExamineObject()

Post by Coder »

@abalaban

Thanks for the example! That will get me started.

Cheers,
Coder
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 218
Joined: Mon Aug 15, 2011 10:20 am
Location: Brisbane, QLD. Australia.

Re: ExamineObject()

Post by colinw »

[...]
int64 fileSize = dat->FileSize;
if ( EXD_IS_LINK(dat) && 0 == fileSize)
{ // it's a link try to resolve it
[...]

Please avoid making assumptions like this, the filesize has no bearing on whether something is
a linked object or not.
Please distribute only example code provided in the latest autodoc file; dos.doc et al.

I believe the latest SDK files will be publicly distributed shortly.
User avatar
tboeckel
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 68
Joined: Mon Jun 20, 2011 9:56 am
Contact:

Re: ExamineObject()

Post by tboeckel »

Coder wrote:I have not seen any examples around on the net using the ExamineObject().
Then you didn't look carefully enough. YAM is using ExamineObject() from the very first day since this function started to exist.
Last edited by tboeckel on Tue Mar 12, 2013 9:06 am, edited 1 time in total.
User avatar
abalaban
Beta Tester
Beta Tester
Posts: 456
Joined: Mon Dec 20, 2010 2:09 pm
Location: France
Contact:

Re: ExamineObject()

Post by abalaban »

colinw wrote:[...]
int64 fileSize = dat->FileSize;
if ( EXD_IS_LINK(dat) && 0 == fileSize)
{ // it's a link try to resolve it
[...]

Please avoid making assumptions like this, the filesize has no bearing on whether something is
a linked object or not.
Please distribute only example code provided in the latest autodoc file; dos.doc et al.

I believe the latest SDK files will be publicly distributed shortly.
Yes Colin, you are right, it was a short example I extracted from an existing code and in this code I had to resolve the link only when the fileSize was 0. The fact it has null size does not imply anything on the fact the file is a link or not of course.

Source code modified to prevent bad assumptions.
AmigaOne X1000 running AOS 4 beta
AmigaOne XE/G4
Amiga 1200/PPC 603e + BVision PPC
Post Reply