← Back to team overview

kicad-developers team mailing list archive

Project file '' not found on first execution of Kicad

 

Hi folks,

Right now, when a user installs KiCad successfully on an OS X system, and
they start Kicad, the first thing they see is an error box.

It states

'Error

Project file '' not found'

I do not think new users should get an error immediately upon opening Kicad.

I tried to fix this today, but I ran into some conceptual issues, so
hopefully I can get them cleared up and submit a patch for this.

First, there appears to be code to prevent this from happening.

in kicad/prjconfig.cpp:
    wxString prj_filename = GetProjectFileName();
    xString nameless_prj = NAMELESS_PROJECT  wxT( ".pro" );

    // Check if project file exists and if it is not noname.pro
    if( !wxFileExists( prj_filename ) && !prj_filename.IsSameAs(
nameless_prj ) )
    {
        wxString msg = wxString::Format( _(
                "KiCad project file '%s' not found" ),
                GetChars( prj_filename ) );

        DisplayError( this, msg );
        return;
    }

(NAMELESS_PROJECT is set to "noname" in include/common.h).

This checks to see if GetProjectFileName() exists as a file, and if it
doens't, it checks to see if it is "noname.pro", and if not, it pops up an
error.

In kicad/kicad.cpp,

    if( App().argc > 1 )
        frame->SetProjectFileName( App().argv[1] );

    else if( GetFileHistory().GetCount() )
    {
        wxString last_pro = GetFileHistory().GetHistoryFile( 0 );

        if( !wxFileExists( last_pro ) )
        {
            GetFileHistory().RemoveFileFromHistory( 0 );

            wxFileName namelessProject( wxGetCwd(), NAMELESS_PROJECT,
                                        ProjectFileExtension );

            frame->SetProjectFileName( namelessProject.GetFullPath() );
        }
        else
        {
            // Try to open the last opened project,
            // if a project name is not given when starting Kicad
            frame->SetProjectFileName( last_pro );

            wxCommandEvent cmd( 0, wxID_FILE1 );

            frame->OnFileHistory( cmd );
            prjloaded = true;    // OnFileHistory() loads the project
        }
    }


we check if we have any command line arguments, and if we don't, we check
to see if we have a history, and if we can't load the top history result,
we set the project filename to the current working directory / noname.pro.

I see two potential issues here:

1) The situation where we have no history isn't handled explicitly, which
is part of what causes this issue for new users, I think.

2) When there is a history, but it can't find the top result, it sets the
project filename to the current working directory / noname.pro.  Over in
prjconfig.cpp, when we check for noname.pro, we check if the whole string
is "noname.pro".

My gut feeling is to do something like the following:

    if( App().argc > 1 )
        // if there was a path specified, i.e. "kicad path/to/project.pro"
        frame->SetProjectFileName( App().argv[1] );

    else if( ! GetFileHistory().GetCount() )
    {
        // if there wasn't a .pro specified, and there is no history
        wxFileName namelessProject( NAMELESS_PROJECT,
                                    ProjectFileExtension );

        frame->SetProjectFileName( namelessProject.GetFullName() );
    }
    else
    {
        // if there wasn't a .pro specified, and there is a history

        wxString last_pro = GetFileHistory().GetHistoryFile( 0 );

        if( !wxFileExists( last_pro ) )
        {
            GetFileHistory().RemoveFileFromHistory( 0 );

            wxFileName namelessProject( NAMELESS_PROJECT,
                                        ProjectFileExtension );

            frame->SetProjectFileName( namelessProject.GetFullName() );
        }
        else
        {
            // Try to open the last opened project,
            // if a project name is not given when starting Kicad
            frame->SetProjectFileName( last_pro );

            wxCommandEvent cmd( 0, wxID_FILE1 );

            frame->OnFileHistory( cmd );
            prjloaded = true;    // OnFileHistory() loads the project
        }
    }

But on the other hand, I don't know if this breaks assumptions other places
by having the ProjectFileName just be "noname.pro".  Would it be better to
change the check to see if the project filename ends with "/noname.pro"? I
hope to get a better feel for things like this as I gain familiarity with
the extensive codebase.

Also, Wayne, March 16th 2014, we discussed something like this on the list,
and you mentioned you use a custom default project file and want to be
alerted when that isn't found.  I am not familiar with how that workflow
works.  Would it be broken by this fix?

Adam Wolf
Cofounder and Engineer
W&L

Follow ups