INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: IMJFileAutomation.SilentDeleteFile() Isn't Silent  (Read 1920 times)

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
IMJFileAutomation.SilentDeleteFile() Isn't Silent
« on: December 12, 2012, 03:36:56 pm »

I'm writing a method that will replace an existing file in MC's Database with a new file.  The issue is that AutoImport may have already picked up the new file before I get to it, so I want to first check the database and remove the file from MC (the same as hitting delete and choosing the first choice in the resulting dialog).

I've tried to use IMJFileAutomation.SilentDeleteFile() and discovered that it doesn't work right.  It actually still prompts you to confirm, despite supposedly being the "silent" version of the method.  (NOTE:  I'm actually testing with MC17 right now, though, so yell if this is fixed in a newer version.)

I also wonder (and was planning to test it out for this purpose)...

Does this function, should it actually be working correctly, do what I want?  I want to remove the file in question from MC's Library, not delete it from disk.  Another tactic I thought might work would be to change the DB Location from Main to Removed.  Unfortunately, unless my brain is addled or something, I'm unable to find the appropriate long references to use for the nAppendDBLocations and/or nRemoveDBLocations parameters.  It says in the wiki:

Quote
    nAppendDBLocations: Which portions to add the file to. Value is a bitwise OR of
        DB_LOCATION_INVALID
        DB_LOCATION_MAIN
        DB_LOCATION_PLAYING_NOW
        DB_LOCATION_CD
        DB_LOCATION_EXPLORER
        DB_LOCATION_UNASSIGNED
        DB_LOCATION
        DB_LOCATION_FILE_TRANSFER
        DB_LOCATION_HANDHELD
        DB_LOCATION_GROUPING
        DB_LOCATION_REMOVED
        DB_LOCATION_DOWNLOADING
        DB_LOCATION_PODCAST_FEED
    nRemoveDBLocations: Which portions to remove the file from, same value as nAppendDBLocations

But I can't find the long values that go with this anywhere.  Anyone know what parameters would I use to add a file to the Removed DB and remove it from the Main DB?
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: IMJFileAutomation.SilentDeleteFile() Isn't Silent
« Reply #1 on: December 12, 2012, 05:11:04 pm »

It actually still prompts you to confirm, despite supposedly being the "silent" version of the method.

Looking at the MC18 code, it seems like it would be silent to me.  But I also don't think anything has changed since MC17.

And if the dialog doesn't show, it'll remove from the library and not delete from disk.
Logged
Matt Ashland, JRiver Media Center

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: IMJFileAutomation.SilentDeleteFile() Isn't Silent
« Reply #2 on: December 12, 2012, 05:35:35 pm »

When I was testing earlier today on MC17, it was absolutely showing the popup "which way do you want to delete" dialog.  I'm not, however, absolutely positive that I was using the most current build of MC17 on that machine, but it wasn't ancient.

But... For whatever reason, the exact same code works perfectly on my machine at home with the current build of 18.  So, consider me satiated here for now.  I'll double check MC17 tomorrow (after making sure to update it if needed) and let you know if/how it is acting differently, if so.

PS.  Today was perhaps the Most Annoying Day Ever.  I was stuck at an all-day seminar providing support where each speaker's talk was only allotted 10 minutes (which means, in my view, the schedule is "theoretical").  Every ten minutes, or so (usually 15 actually, so we ran way overtime), I had to pop up and go:

1. Give someone a microphone.
2. Make sure they didn't put it on upside down or at their navel (Side note: Why, oh why, do people put lapel microphones on way down by their belly buttons?  Do you talk out of your navel?  Are you afraid it is going to bite you in the face or something?)
3. Hit a button on the KVM to swap computers as needed.
4. Open their PowerPoint file for them, because they're almost always too nervous/confused to manage this themselves in a reasonable fashion.
5. And walk back to my chair and sit down.

Repeat the above about 50 times and you have my day.

But, the upside was I got a TON done on my project, so that was nice.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: IMJFileAutomation.SilentDeleteFile() Isn't Silent
« Reply #3 on: December 14, 2012, 12:59:29 pm »

Yep.  Confirmed.

MC 17.0.189 does not perform IMJFileAutomation.SilentDeleteFile() correctly, at least not from .NET.

When you run it, it shows the "normal" File Deletion popup (Remove, Recycle, Delete).  Then, no matter what you choose in this dialog, it then throws an Exception (though it does actually do the deletion, it just then crashes).  Details:

Code: [Select]
Exception Message: The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
HRESULT: -2147417851
InnerException: null
Source: mscorlib
StackTrace:
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at MediaCenter.IMJFileAutomation.SilentDeleteFile()
   at MCnet.MC.ReplaceFile(IMJFileAutomation oldFile, String newFilename, Boolean removeSourceFile) in c:\Users\emr\Development\Libraries\MCnet\MC.cs:line 1865
   at MCnet.MC.ReplaceFileExtension(IMJFileAutomation oldFile, String newExtension, Boolean removeSourceFile) in c:\Users\emr\Development\Libraries\MCnet\MC.cs:line 2063
   at MCnet.MC.ReplaceFile(ReplaceMode replaceMode, IMJFileAutomation oldFile, String newFilename, String newExtension, Boolean removeSourceFile) in c:\Users\emr\Development\Libraries\MCnet\MC.cs:line 1942
   at MCnet.MC.ReplaceFile(ReplaceMode replaceMode, IMJFileAutomation oldFile, String newFilename, String newExtension) in c:\Users\emr\Development\Libraries\MCnet\MC.cs:line 1914
   at MCTester.Program.Main(String[] args) in c:\Users\emr\Development\Projects\MCTester\MCTester\Program.cs:line 52
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
TargetSite: {System.Object ForwardCallToInvokeMember(System.String, System.Reflection.BindingFlags, System.Object, Int32[], System.Runtime.Remoting.Proxies.MessageData ByRef)}

I should make it clear:  Not only does my application get this exception, but doing this also causes MC itself to crash (no matter what you choose in the popup dialog, including cancel).

The current build of MC18 does not have this problem.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: IMJFileAutomation.SilentDeleteFile() Isn't Silent
« Reply #4 on: December 14, 2012, 01:51:34 pm »

One other note:

I don't really care (much) if you fix this or not, since it works on MC18.  However, if you could let me know if you think you'll build a new version of MC17 with this or not at some point, that'd be great.

The thing I'm building right now depends pretty completely on this, so if it won't be fixed, I'll have to either block MC17 entirely, or come up with some sort of MC17 workaround for it (which will probably be pretty ugly, and I'm feeling pretty lazy on that).  I haven't bothered to test older builds of MC17 or previous major versions.  From searching the forums, it doesn't look like many people are using this function, but I need it.

Details:  I'm using it because my application needs to replace the Filename "tag" for an existing file in MC with a new "version" of the file.

The idea is that you run an external conversion (TS > MKV or whatever) and then this grabs the new file, and replaces the existing reference in MC's database with the new one (so you don't lose any metadata post-conversion).  But, I think a modified version could also be extremely handy for the old "re-ripped old MP3 files to FLAC and now want to replace the existing items with the new rip" problem.  So, it basically just takes an existing IMJFileAutomation object and replaces the Filename tag with the updated reference, and then does some SaveToTag() and UpdateFromFile() acrobatics to make sure all the fields come out smelling clean.

Before it does this, it has to remove the "destination file" from MC's database completely (even the Removed Files part of the database).  If I omit this, subsequent calls (even from different applications) get confused when they find two items in MC's database that point to the same source file (it seems like it just picks one, but seems to prefer the one in the Removed Items database for whatever reason).

I can't trust that the "new file" hasn't already been picked up by AutoImport, so I have to assume that the file might be in MC's database already and find it and remove it.  Plus, even if it isn't there already, I'm actually importing the file manually, so that I can "test" the [Media Type] of the files and make sure they match (you wouldn't want to replace a Video file with an Audio file, generally, so I do a sanity check).
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/
Pages: [1]   Go Up