Author Topic: Small Bug in Scripted wizard?  (Read 5851 times)

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Small Bug in Scripted wizard?
« on: January 24, 2012, 07:32:29 pm »
I think I found a bug in the scripted wizard plugin. But I am quite new to this part of C::B. So here is what I found:

Before a file gets generated within GenerateFile(), the check if the file does exist is done in the directory of the project which was active when the wizard was started. So it complains that a file already exists but is is in a different project. (It even askes if it can overwrite the file.)

Is there a reason to not move the check to the point where the full path is constructed?

Code
Index: wiz.cpp
===================================================================
--- wiz.cpp (revision 7713)
+++ wiz.cpp (working copy)
@@ -667,22 +667,6 @@
 {
     wxFileName fname(filename);
 
-    if ( fname.FileExists() )
-    {
-        wxString query_overwrite;
-        query_overwrite.Printf(
-          _T("Warning:\n")
-          _T("The wizard is about OVERWRITE the following existing file:\n")+
-          fname.GetFullPath()+_T("\n\n")+
-          _T("Are you sure that you want to OVERWRITE the file?\n\n")+
-          _T("(If you answer 'No' the existing file will be kept.)"));
-        if (cbMessageBox(query_overwrite, _T("Confirmation"),
-                         wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT) == wxID_NO)
-        {
-            return fname.GetFullPath();
-        }
-    }
-
     // extension sanity check
     FileType ft = FileTypeOf(fname.GetFullPath());
     switch (ft)
@@ -731,6 +715,21 @@
     }
 
     fname = basePath + wxFILE_SEP_PATH + fname.GetFullPath();
+    if ( fname.FileExists() )
+    {
+        wxString query_overwrite;
+        query_overwrite.Printf(
+          _T("Warning:\n")
+          _T("The wizard is about OVERWRITE the following existing file:\n")+
+          fname.GetFullPath()+_T("\n\n") +
+          _T("Are you sure that you want to OVERWRITE the file?\n\n")+
+          _T("(If you answer 'No' the existing file will be kept.)"));
+        if (cbMessageBox(query_overwrite, _T("Confirmation"),
+                         wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT) == wxID_NO)
+        {
+            return fname.GetFullPath();
+        }
+    }
 
     // create the file with the passed contents
     wxFileName::Mkdir(fname.GetPath(),0777,wxPATH_MKDIR_FULL);

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Small Bug in Scripted wizard?
« Reply #1 on: January 24, 2012, 08:54:22 pm »
Is there a reason to not move the check to the point where the full path is constructed?
No, this might be a bug introduced with changes done in the project management... some time ago already. ::)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Small Bug in Scripted wizard?
« Reply #2 on: January 24, 2012, 08:54:44 pm »
Is there a reason to not move the check to the point where the full path is constructed?

I don't see any reasons, not to move, but one reason to move it, because it overwrites files without asking, and that should of course not happen.

So my opinion:
it should definitely be committed, because it really is a (serious) bug and acts contrary to what it is meant to do.