Opened 16 years ago

Last modified 8 years ago

#3231 assigned bug

File type problems with Paladin in Haiku, not BeOS

Reported by: PieterPanman Owned by: nobody
Priority: normal Milestone: R1
Component: Applications/Tracker Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

I installed DarkWyrm's Paladin, a BeIDE replacement. I'm running into some filetype issues that don't exist in BeOS. When I create a project file, its file type is messed up.

To reproduce:

  • Install Paladin 1.0 RC from Bebits
  • Run it and create a new project
  • Save it and exit

In Tracker, the file home/MyProject/MyProject.pld is identified as a generic file. See BeforeOpening.png. However, when I catattr the file, it returns a Paladin file type:

~/projects/MyProject> catattr BEOS:TYPE MyProject.pld 
MyProject.pld : string : text/x-vnd.dw-Paladin.Project

Paladin installed the FileType association correctly as far as I can see. (see PaladinFileType.png) Double clicking the file opens it in StyleEdit. It also doesn't have the correct icon.

When I Identify the file, it is identified as a Text File (text/plain).

With the File Type addon I changed its type to text/x-vnd.dw-Paladin.Project. Now this type is also seen by catattr, and also by Tracker ("Paladin Project" as the kind).

However, when I open the project and close it, it is saved and the same issue as above occurs again.

I don't know where tracker gets its information, but if catattr BEOS:TYPE returns text/x-vnd.dw-Paladin.Project, it should find the type to be a Paladin Project.

Attachments (3)

BeforeOpening.png (12.3 KB ) - added by PieterPanman 16 years ago.
PaladinFileType.png (44.7 KB ) - added by PieterPanman 16 years ago.
test3231.cpp (1.4 KB ) - added by darkwyrm 14 years ago.
Code which reproduces the current state of the bug - hrev41787

Download all attachments as: .zip

Change History (17)

by PieterPanman, 16 years ago

Attachment: BeforeOpening.png added

by PieterPanman, 16 years ago

Attachment: PaladinFileType.png added

comment:1 by darkwyrm, 16 years ago

Here is the exact problem:

When a project is saved, Paladin updates type attribute even when it is not needed. I *think* the problem lies somewhere in the icon-related code at the beginning of BPoseView::AttributeChanged().

comment:2 by darkwyrm, 16 years ago

The code that causes the bug goes like this:

BFile file("somefile",B_SOME_FLAGS); file.WriteAttrString("application/x-vnd.dw-Paladin.Project");

However, when using the following code in the same place, it does NOT occur:

BFile file("somefile",B_SOME_FLAGS); BNodeInfo nodeInfo(&file); nodeInfo.SetType("application/x-vnd.dw-Paladin.Project");

When the bug occurs, the file type of the project in question goes from the project mime type to text/plain. I hope all of this helps track down the problem.

comment:3 by stippi, 16 years ago

Hm, that doesn't look like it would work. Can you please post the actual code? What attribute name string do you use when using the file directly? Should be "BEOS:TYPE" and "application/x-vnd.dw-Paladin.Project" should actually be passed inside a BString! And the second question would be with what permissions you construct the BFile exactly. I suppose you just wrote the project file, so you probably have write permissions set. Maybe that's different from how BNodeInfo works, I don't know. It should still work, though, so the true WriteAttrString() call is the most interesting.

comment:4 by darkwyrm, 16 years ago

Whoops! I guess that's what I get for trying to write code from memory. ;) Here is an exact copy of the code that duplicates the error.

BFile file(path,B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
if (file.InitCheck() != B_OK)
{
	STRACE(2,("Couldn't create project file %s. Bailing out\n",path));
	return;
}

STRACE(2,("Saved Project %s. Data as follows:\n%s\n",path,data.String()));

file.Write(data.String(),data.Length());

fPath = path;
fObjectPath = fPath.GetFolder();

BString objfolder("(Objects.");
objfolder << GetName() << ")";
fObjectPath.Append(objfolder.String());

BString str(PROJECT_MIME_TYPE);
file.WriteAttrString("BEOS:TYPE",&str);

UpdateBuildInfo();


PROJECT_MIME_TYPE is #defined elsewhere as "text/x-vnd.dw-Paladin.Project". The changes made to the code which do not show the bug replace the last three lines of code with this:

BNodeInfo nodeInfo(&file);
nodeInfo.SetType(PROJECT_MIME_TYPE);

UpdateBuildInfo();

comment:5 by anevilyak, 16 years ago

The problem could be that the type attribute is actually supposed to be B_MIME_TYPE, not B_STRING_TYPE. WriteAttrString assumes the latter, which could be what's triggering this issue.

comment:6 by anevilyak, 16 years ago

To verify this, try replacing with file.WriteAttr("BEOS:TYPE", B_MIME_TYPE, 0, PROJECT_MIME_TYPE, strlen(PROJECT_MIME_TYPE));

comment:7 by darkwyrm, 16 years ago

Excellent idea, anevilyak, but to no avail. Using the WriteAttr() code you posted, it exhibits the same behavior as when I use WriteAttrString.

All that I need to do is open a project and close it in both cases. Paladin saves the project and updates the MIME type. Using WriteAttr or WriteAttrString, the project icon disappears and, if double-clicked, gets opened in StyledEdit as a plaintext file. Using the BNodeInfo version, the project icon stays the way it should and double-clicking on the file opens it in Paladin like it should.

comment:8 by bonefish, 16 years ago

I'd assume WriteAttr[String]() fails for some reason. The being identified as text/plain is probably because the project type doesn't have a sniffer rule (or does it?). So the obvious question is: What's the error code WriteAttr[String]() returns? Maybe that gives a lead on what goes wrong.

comment:9 by darkwyrm, 16 years ago

WriteAttr isn't failing -- it returns 29, which == strlen(PROJECT_MIME_TYPE).

I did a bunch of looking around in the Tracker and sniffer sources and, while I'm not very familiar at all with the sources, I didn't find anything that looked amiss at first glance.

The project mime type and data are AFAIK properly installed. My development box runs R5, Zeta 1.2, and (right now) Haiku GCC4. The MIME stuff works exactly the same on both R5 and Zeta and everything works right, too. Just for completeness sake I've posted below the code that installs Paladin's project MIME type.

void
InitFileTypes(void)
{
	BMimeType mime;
	BString string;
	BMessage msg,ext;
	
	BBitmap	large_icon(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_COLOR_8_BIT);
	memcpy(large_icon.Bits(),kProjectLargeIconBits,1024);
	BBitmap	mini_icon(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_COLOR_8_BIT);
	memcpy(mini_icon.Bits(),kProjectSmallIconBits,256);
	
	mime.SetType(PROJECT_MIME_TYPE);
	mime.SetShortDescription("Paladin Project");
	mime.SetLongDescription("File to build a program with Paladin");
	mime.SetIcon(&large_icon, B_LARGE_ICON);
	mime.SetIcon(&mini_icon, B_MINI_ICON);
	mime.SetPreferredApp(APP_SIGNATURE);
	mime.Install();
	
	ext.AddString("extensions","pld");
	mime.SetFileExtensions(&ext);
}

comment:10 by scottmc, 14 years ago

Does this still happen with Paladin1.3 which is now available as an OptionalPackage?

in reply to:  10 comment:11 by darkwyrm, 14 years ago

Replying to scottmc:

Does this still happen with Paladin1.3 which is now available as an OptionalPackage?

I would assume that the bug still exists, but you won't find it by running Paladin under Haiku -- I patched Paladin's sources to work around the bug.

If I get a little time this weekend (which I should), I'll see if I can write some test code which reproduces the bug.

comment:12 by scottmc, 14 years ago

Any progress on this one?

comment:13 by darkwyrm, 14 years ago

Kind of. I just spent a little time fiddling with it and the bug is partially fixed. The type part works properly, both in the test code I wrote and by undoing the workaround in the current development version of Paladin on my hard drive. The only problem now is the icon. Using WriteAttrString causes the MIME type to be properly written and I can double-click on the project file and it is opened in Paladin like it should be. The only problem is that the icon for the project is set to the generic one and is updated to the Paladin Project icon only when Paladin saves the file using the old way. If the icon is already set to the right one, saving the project using WriteAttrString causes it to be lost -- reverted to the generic file icon. I'm attaching some test code which reproduces what I'm talking about.

by darkwyrm, 14 years ago

Attachment: test3231.cpp added

Code which reproduces the current state of the bug - hrev41787

comment:14 by axeld, 8 years ago

Owner: changed from axeld to nobody
Status: newassigned
Note: See TracTickets for help on using tickets.