Update of /cvsroot/mahogany/M/src/classes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24257/src/classes

Modified Files:
        MessageView.cpp 
Log Message:
don't delete the temporary files when the viewer process terminates, sometimes 
they're still needed (when this process simply forwards the file to another one)

Index: MessageView.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MessageView.cpp,v
retrieving revision 1.162
retrieving revision 1.163
diff -b -u -2 -r1.162 -r1.163
--- MessageView.cpp     15 May 2005 21:16:51 -0000      1.162
+++ MessageView.cpp     23 Jun 2005 20:57:37 -0000      1.163
@@ -157,14 +157,11 @@
 // are created by LaunchProcess() and deleted when the viewer process
 // terminates. If it terminates with non 0 exit code, errormsg is given to the
-// user. The tempfile is the name of a temp file containing the data passedto
-// the viewer (or NULL if none) and will be removed after viewer terminates.
+// user.
 class ProcessInfo
 {
 public:
    ProcessInfo(wxProcess *process,
-
                int pid,
-               const String& errormsg,
-               const String& tempfilename)
+               const String& errormsg)
       : m_errormsg(errormsg)
    {
@@ -173,17 +170,9 @@
       m_process = process;
       m_pid = pid;
-
-      if ( !tempfilename.empty() )
-         m_tempfile = new MTempFileName(tempfilename);
-      else
-         m_tempfile = NULL;
    }
 
    ~ProcessInfo()
    {
-      if ( m_process )
          delete m_process;
-      if ( m_tempfile )
-         delete m_tempfile;
    }
 
@@ -198,12 +187,8 @@
    void Detach() { m_process->Detach(); m_process = NULL; }
 
-   // return the pointer to temp file object (may be NULL)
-   MTempFileName *GetTempFile() const { return m_tempfile; }
-
 private:
    String         m_errormsg; // error message to give if launch failed
    wxProcess     *m_process;  // wxWindows process info
    int            m_pid;      // pid of the process
-   MTempFileName *m_tempfile; // the temp file (or NULL if none)
 };
 
@@ -3420,7 +3405,8 @@
    if ( pid != -1 )
    {
-      ProcessInfo *procInfo = new ProcessInfo(process, pid, errormsg, 
filename);
+      ProcessInfo *procInfo = new ProcessInfo(process, pid, errormsg);
 
       m_processes.Add(procInfo);
+      m_tempFiles.Add(filename);
    }
 
@@ -3455,20 +3441,39 @@
 void MessageView::DetachAllProcesses()
 {
-   size_t procCount = m_processes.GetCount();
-   for ( size_t n = 0; n < procCount; n++ )
+   size_t n;
+
+   // delete all process info objects, we don't need notifications about
+   // process termination any more
+   const size_t procCount = m_processes.GetCount();
+   for ( n = 0; n < procCount; n++ )
    {
       ProcessInfo *info = m_processes[n];
       info->Detach();
 
-      MTempFileName *tempfile = info->GetTempFile();
-      if ( tempfile )
+      delete info;
+   }
+
+   m_processes.Empty();
+
+
+   // also delete the temporary files used by them
+   bool closedAll = true;
+   const size_t tmpCount = m_tempFiles.GetCount();
+   for ( n = 0; n < tmpCount; n++ )
+   {
+      const wxString& fn = m_tempFiles[n];
+      if ( wxRemove(fn) != 0 )
       {
-         String tempFileName = tempfile->GetName();
-         wxLogWarning(_("Temporary file '%s' left because it is still in "
-                        "use by an external process"), tempFileName.c_str());
+         wxLogSysError(_("Failed to delete file \"%s\""), fn.c_str());
+         closedAll = false;
+      }
       }
 
-      delete info;
+   if ( !closedAll )
+   {
+      wxLogWarning(_("Some of the temporary files couldn't have been 
removed."));
    }
+
+   m_tempFiles.Empty();
 }
 



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to