OSDN Git Service

MacGui: Store live previews in a sub directory in "~/Library/Application Support...
authordynaflash <dynaflash@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 6 Aug 2010 04:28:33 +0000 (04:28 +0000)
committerdynaflash <dynaflash@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 6 Aug 2010 04:28:33 +0000 (04:28 +0000)
- Allows multi-instances to encode live previews without overwriting the live preview for any other instance (since previously we assumed single instance so there was just one live preview file for each container.
- Clean up of the previews directory when a single instance is laucnhed to make sure we do not build up a pile of old previews.
- Removed old code for live previews which handled the deprecated avi and ogm containers.

git-svn-id: svn://localhost/HandBrake/trunk@3472 b64f7644-9d1e-0410-96f1-a4d463321fa5

macosx/Controller.h
macosx/Controller.m
macosx/HBPreviewController.m

index e318c39..c94308e 100644 (file)
@@ -291,7 +291,7 @@ BOOL                        fIsDragging;
     
     double                         dockIconProgress;
 }
-
+- (int) getPidnum;
 - (IBAction) showAboutPanel:(id)sender;
 
 - (void) writeToActivityLog:(const char *) format, ...;
index 86674ad..672d440 100644 (file)
@@ -129,6 +129,34 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
      * pid number for this instance in the case of multi-instance encoding. */ 
     hbInstanceNum = [self hbInstances];
     
+    /* If we are a single instance it is safe to clean up the previews if there are any
+     * left over. This is a bit of a kludge but will prevent a build up of old instance
+     * live preview cruft. No danger of removing an active preview directory since they
+     * are created later in HBPreviewController if they don't exist at the moment a live
+     * preview encode is initiated. */
+    if (hbInstanceNum == 1)
+    {
+        NSString *PreviewDirectory = [NSString stringWithFormat:@"~/Library/Application Support/HandBrake/Previews"];
+        PreviewDirectory = [PreviewDirectory stringByExpandingTildeInPath];
+        NSError *error;
+        NSArray *files = [ [NSFileManager defaultManager]  contentsOfDirectoryAtPath: PreviewDirectory error: &error ];
+        for( NSString *file in files ) 
+        {
+            if( file != @"." && file != @".." ) 
+            {
+                [ [NSFileManager defaultManager] removeItemAtPath: [ PreviewDirectory stringByAppendingPathComponent: file ] error: &error ];
+                if( error ) 
+                { 
+                    //an error occurred...
+                    [self writeToActivityLog: "Could not remove existing preview at : %s",[file UTF8String] ];
+                }
+            }    
+        }
+        
+    }
+    
+     
+    
     /* Call UpdateUI every 1/2 sec */
     
     [[NSRunLoop currentRunLoop] addTimer:[NSTimer
@@ -284,13 +312,19 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                 [self writeToActivityLog: "Pid for this instance:%d", pidNum];
                 /* Tell fQueueController what our pidNum is */
                 [fQueueController setPidNum:pidNum];
+                
+                hbInstances++;
             }
-            hbInstances++;
         }
-       }
+    }
     return hbInstances;
 }
 
+- (int) getPidnum
+{
+    return pidNum;
+}
+
 #pragma mark -
 
 - (void) didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
index 7fa8a84..c0db129 100644 (file)
     
     [fHBController prepareJobForPreview];
     
+    /* Make sure we have a Preview sub directory with our pidnum attached */
+    NSString *PreviewDirectory = [NSString stringWithFormat:@"~/Library/Application Support/HandBrake/Previews/%d", [fHBController getPidnum]];
+    PreviewDirectory = [PreviewDirectory stringByExpandingTildeInPath];
+    if( ![[NSFileManager defaultManager] fileExistsAtPath:PreviewDirectory] )
+    {
+        [[NSFileManager defaultManager] createDirectoryAtPath:PreviewDirectory 
+                                  withIntermediateDirectories:NO 
+                                                   attributes:nil 
+                                                        error:nil];
+    }
     /* Destination file. We set this to our preview directory
      * changing the extension appropriately.*/
     if (fTitle->job->mux == HB_MUX_MP4) // MP4 file
     {
         /* we use .m4v for our mp4 files so that ac3 and chapters in mp4 will play properly */
-        fPreviewMoviePath = @"~/Library/Application Support/HandBrake/Previews/preview_temp.m4v";
+        fPreviewMoviePath = [PreviewDirectory stringByAppendingString:@"/preview_temp.m4v"];
     }
     else if (fTitle->job->mux == HB_MUX_MKV) // MKV file
     {
-        fPreviewMoviePath = @"~/Library/Application Support/HandBrake/Previews/preview_temp.mkv";
-    }
-    else if (fTitle->job->mux == HB_MUX_AVI) // AVI file
-    {
-        fPreviewMoviePath = @"~/Library/Application Support/HandBrake/Previews/preview_temp.avi";
-    }
-    else if (fTitle->job->mux == HB_MUX_OGM) // OGM file
-    {
-        fPreviewMoviePath = @"~/Library/Application Support/HandBrake/Previews/preview_temp.ogm";
+        fPreviewMoviePath = [PreviewDirectory stringByAppendingString:@"/preview_temp.mkv"];
     }
     
     fPreviewMoviePath = [[fPreviewMoviePath stringByExpandingTildeInPath]retain];
     
+    [fHBController writeToActivityLog: "Movie Preview path attempt: %s",[fPreviewMoviePath UTF8String] ];
+    
+    
     /* See if there is an existing preview file, if so, delete it */
     if( ![[NSFileManager defaultManager] fileExistsAtPath:fPreviewMoviePath] )
     {