Getting an unfinished file from TransferView

Problems compiling? Don't understand the source code? Don't know how to code your feature? Post here.

Moderator: Moderators

Locked
Snuttan
Posts: 6
Joined: 2006-02-08 16:06

Getting an unfinished file from TransferView

Post by Snuttan » 2006-02-08 16:23

Hi there!

Well as the topic might have revealed I'm in need of getting the file name of the temporary file in the unfinished folder that is currently selected by the user. I also need the path to the unfinished folder.

What I want to do is add a function that lets the user right click on any file and choose "Stream in VLC", which opens the temporary file in VLC. What I've got this far is the following code:

Code: Select all

LRESULT TransferView::onStream(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	
	int i = -1;
	while( ( i = ctrlTransfers.GetNextItem(i, LVNI_SELECTED) ) != -1)
	{
		ItemInfo* itemInfo = ctrlTransfers.getItemData(i);
		tstring filePath = itemInfo->getText(COLUMN_PATH);
		tstring fileName = itemInfo->getText(COLUMN_FILE);
		tstring str = _T("\"c:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" \"");

		str += filePath;
		str += fileName;
		str += _T("\"");
                                 LPCTSTR p = str.c_str();
		MessageBox(p, (LPCTSTR)"dafd");
		_wsystem(str.c_str());
	}
	return 0;
}


Now I know I shouldn't hard code the path to VLC or ever hard code that VLC has to be used here, but I'm still in a very early phase here so try to look past that. The message box is just for simple debugging, I wanted to se exactly what I was sending into _wsystem() function.

The main issue here is that filePath and fileName contains the path and name of the soon to be finished file, but that is not what I want. What I want is the unfinished path and the name of the temporary file in it so that I can stream it while it is downloading. I have searched for it but to be honest I really don't even know where to look so if someone could just give med a hint or something I would really appreciate it.

ullner
Forum Moderator
Posts: 333
Joined: 2004-09-10 11:00
Contact:

Post by ullner » 2006-02-08 16:38

Have a look at getTempTarget.

Big Muscle
Posts: 72
Joined: 2004-01-23 14:45

Post by Big Muscle » 2006-02-09 05:19

I use this:

Code: Select all

		ItemInfo *ii = ctrlTransfers.getItemData(i);

		QueueItem::StringMap queue = QueueManager::getInstance()->lockQueue();

		string tmp = ii->Target;
		QueueItem::StringIter qi = queue.find(&tmp);

		string aTempTarget;
		if(qi != queue.end())
			aTempTarget = qi->second->getTempTarget();

		QueueManager::getInstance()->unlockQueue();

		WinUtil::RunPreviewCommand(wID - IDC_PREVIEW_APP, aTempTarget);

Snuttan
Posts: 6
Joined: 2006-02-08 16:06

Post by Snuttan » 2006-02-09 16:59

Hi, thanks for the reply and sorry to be a bother but I can't seem to find: string Target in ItemInfo as you described. What exactly does Target hold? Is it just the file name, the path and file name or none of the above?

So what I'm set out on doing is just finding the QueueItem that is currently selected so I can get a hold of the temp name of the file, and then to get the path of the unfinished directory.

Big Muscle
Posts: 72
Joined: 2004-01-23 14:45

Post by Big Muscle » 2006-02-10 05:09

ah, sorry :) ii->Target is (ii->path + ii->file)

Snuttan
Posts: 6
Joined: 2006-02-08 16:06

Post by Snuttan » 2006-02-10 20:42

Thanks alot for all the help, this is what I ended up with in case anyone is intrested in doing something similar.

Code: Select all

LRESULT TransferView::onStream(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	
	int i = -1;
	while( ( i = ctrlTransfers.GetNextItem(i, LVNI_SELECTED) ) != -1)
	{
		
		ItemInfo* itemInfo = ctrlTransfers.getItemData(i);
		tstring target = itemInfo->getText(COLUMN_PATH) + itemInfo->getText(COLUMN_FILE);
		QueueItem::StringMap queue = QueueManager::getInstance()->lockQueue();
		QueueItem::StringIter iter = queue.find( &(Text::fromT(target)) );

		if(iter != queue.end())
		{
			string VLCPath = "\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" \"";
			string tempTarget = iter->second->getTempTarget();
			string execPath = VLCPath + tempTarget + "\"";
			WinExec(execPath.c_str(), SW_SHOWNORMAL);
		}

		else
		{
			MessageBox(_T("Please make sure a connection \nhas been established to the uploader"), _T("Can't stream this file"));
		}

		QueueManager::getInstance()->unlockQueue();
	}
	return 0;
}
I tried to figure out a way to get the local path to vlc dynamicaly and perhaps give out an error message if it wasen't found, but the best I could think of was the windows registry, but that is just not going to happen:P

PseudonympH
Forum Moderator
Posts: 366
Joined: 2004-03-06 02:46

Post by PseudonympH » 2006-02-10 20:49

Why not simply look in HKEY_CLASSES_ROOT for the program to open e.g. .avi files? Seems much cleaner.

bastya_elvtars
Posts: 164
Joined: 2005-01-06 08:39
Location: HU
Contact:

Post by bastya_elvtars » 2006-02-11 06:23

PseudonympH wrote:Why not simply look in HKEY_CLASSES_ROOT for the program to open e.g. .avi files? Seems much cleaner.
I think VLC is the only one that can open these DCTMP files properly. I would ask the VLC developoers to make an installer that either adds an environment variable of the VLC path, or adds VLC to Path environment variable. Or let the user manually choose it, like in CZDC++.
Hey you, / Don't help them to bury the light... / Don't give in / Without a fight. (Pink Floyd)

Snuttan
Posts: 6
Joined: 2006-02-08 16:06

Post by Snuttan » 2006-02-11 08:22

I could look for the VLC path in HKEY_LOCKAL_MACHINE\\Software\\VideoLAN but I'm not very skilled in reading from the registry and I couldn't find a good tutorial for it either so I quickly abandonned that idea.

So then I thought that VLC perhaps created an environment variable, but they didn't, and asking them to do it just for me would be kind of useless, since then my streaming function would only work for me which it already does with the hardcoded path.

So when I get the time for it, I will probably try to make a setting in the settings gui where you fill in the path, and if you don't then the streaming function will tell you to fill it in. Does this seem reasonable or do you think it's stupid not to simply learn registry management?

bastya_elvtars
Posts: 164
Joined: 2005-01-06 08:39
Location: HU
Contact:

Post by bastya_elvtars » 2006-02-11 08:51

The best is to make the user fill it in/browse for it, since there are also zip packages for VLC so there are no entries created in that case.
Hey you, / Don't help them to bury the light... / Don't give in / Without a fight. (Pink Floyd)

ullner
Forum Moderator
Posts: 333
Joined: 2004-09-10 11:00
Contact:

Post by ullner » 2006-02-11 10:11

Snuttan wrote:I could look for the VLC path in HKEY_LOCKAL_MACHINE\\Software\\VideoLAN but I'm not very skilled in reading from the registry and I couldn't find a good tutorial for it either so I quickly abandonned that idea.
Have a look at RegOpenKeyEx in DC++.

Snuttan
Posts: 6
Joined: 2006-02-08 16:06

Post by Snuttan » 2006-02-12 15:34

The best is to make the user fill it in/browse for it, since there are also zip packages for VLC so there are no entries created in that case.
Very good point, thanks alot for the heads up, when I get the time I'll look into the dc++ gui
Have a look at RegOpenKeyEx in DC++.
I looked into it as you said and it didn't look too hard so I created new version which reads your registry, I could more or less just copy what was written in WinUtil....not too creative I know but no point in reinventing the wheel right? Also I understand what the functions do so I have learned something new so thanks for the tip. One thing I don't fully understand though is why are the RegOpenKeyEx and RegQueryValueEx preceeded by the :: operator when it doesn't seem to be in an unused namespace or class????? It compiles all the same with the :: operator omited from these calls.

Anyway this is what the new code looks like

Code: Select all

LRESULT TransferView::onStream(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	
	int i = -1;
	while( ( i = ctrlTransfers.GetNextItem(i, LVNI_SELECTED) ) != -1)
	{
		
		ItemInfo* itemInfo = ctrlTransfers.getItemData(i);
		tstring target = itemInfo->getText(COLUMN_PATH) + itemInfo->getText(COLUMN_FILE);
		QueueItem::StringMap queue = QueueManager::getInstance()->lockQueue();
		QueueItem::StringIter iter = queue.find( &(Text::fromT(target)) );

		if(iter != queue.end())
		{
			HKEY hk;
			TCHAR buf[512];
			tstring VLC;
			if(::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\VideoLAN\\VLC"), NULL, KEY_READ, &hk) == ERROR_SUCCESS)
			{
				DWORD bufLen = sizeof(buf) * sizeof(TCHAR);
				::RegQueryValueEx(hk, _T("InstallDir"), NULL, NULL, (LPBYTE)buf, &bufLen);
				::RegCloseKey(hk);
				VLC = buf;

				string VLCPath = Text::fromT(VLC);
				VLCPath = "\"" + VLCPath + "\\vlc.exe\" \"";
				string tempTarget = iter->second->getTempTarget();
				string execPath = VLCPath + tempTarget + "\"";
				WinExec(execPath.c_str(), SW_SHOWNORMAL);
			}

			else
			{
				MessageBox(_T("VLC does not appear to be located on this computer, or it was installed using the .zip version.\nPlease use the VLC installer on your windows system"),
							_T("Error locating VLC"));
			}
		}

		else
		{
			MessageBox(_T("Please make sure a connection \nhas been established to the uploader"), _T("Can't stream this file"));
		}

		QueueManager::getInstance()->unlockQueue();
	}
	return 0;
}
I will still try to create gui stuff for those who used the .zip version...but that will come when I have some spare time....kind of rare these days:P

ullner
Forum Moderator
Posts: 333
Joined: 2004-09-10 11:00
Contact:

Post by ullner » 2006-02-14 06:30

Snuttan wrote:One thing I don't fully understand though is why are the RegOpenKeyEx and RegQueryValueEx preceeded by the :: operator when it doesn't seem to be in an unused namespace or class????? It compiles all the same with the :: operator omited from these calls.
I think, the :: is there to call the function(s) in the global scope and override any 'standard' function that's elsewhere.

Snuttan
Posts: 6
Joined: 2006-02-08 16:06

Post by Snuttan » 2006-02-14 17:47

ooh so if there were a namespace clash it would go with the one in the global namespace if one exists in it?

Pothead
Posts: 223
Joined: 2005-01-15 06:55

Post by Pothead » 2006-02-14 21:39

Snuttan wrote:ooh so if there were a namespace clash it would go with the one in the global namespace if one exists in it?
unfortunately dc++ doesn't use many namespaces. :( But from what ullner said, yes. :)

Locked