예제 #1
0
파일: instance.c 프로젝트: jossk/OrangeC
void PassFilesToInstance(void)
{
    int argc = __argc;
    char **argv = __argv;
    AllowSetForegroundWindow(ASFW_ANY);
//	argv = CmdLineToC(&argc, GetCommandLineA());
    if (argv)
    {
        if (argc <= 1)
        {
            SendFileName("###TOP###");
        }
        else
        {
            int i;
            for (i=1; i < argc; i++)
            {
                char buf[260], *p = buf;
                strcpy(buf, argv[i]);
                while (isspace(*p)) p++;
                    if (*p != '/' && *p != '-')
                    {
                        abspath(p, NULL);
                        SendFileName(p);
                    }
            }
        }
    }
}
void Client(char *filename)
{
    int clientSocketDescriptor;
    int connectResult;
    FILE *rdfile;

    rdfile = fopen(filename, "r");
    if (rdfile == NULL)
    {
        puts ("Error while opening file.");
        return;
    }
    clientSocketDescriptor = StartClient("tcp");
    connectResult = ClientConnect(clientSocketDescriptor, "127.0.0.1", 6660);
    if (connectResult == -1)
    {
        return;
    }
    if (SendFileName(clientSocketDescriptor, filename) == -1)
    {
        return;
    }
    if (SendFileSize(clientSocketDescriptor, rdfile) == -1)
    {
        return;
    }
    ClientProcess(clientSocketDescriptor, rdfile);
    ShutdownSocket(clientSocketDescriptor);
    CloseSocket(clientSocketDescriptor);
    fclose(rdfile);

    return;
}
예제 #3
0
int GoProcessing(const tagCMDL & cmdl)
{
	int mode = cmdl.mode;

	CreateDirectory(cmdl.temppath, NULL);

	wchar_t tempfile[MAX_PATH];
	if( lstrlen(cmdl.temppath) == 0 )
	{
		// кодируем в файл по умолчанию
		StringCchCopy(tempfile, MAX_PATH, cmdl.outputfilename);
	}else
	{
		StringCchCopy(tempfile, MAX_PATH, cmdl.temppath);
		if( tempfile[ lstrlen(tempfile) -1 ] != L'\\')
			StringCchCat(tempfile, MAX_PATH, L"\\");
		StringCchCat(tempfile, MAX_PATH, PathFindFileName(cmdl.outputfilename));
	}


	HWND fwwnd = FindWindow(wndclassnameW, NULL);
	if(fwwnd == NULL) return 4;

	int pos = -1;
	while( pos < 0 )
	{
		if( !isProcessExist() ) // проверяем мьютекс
			return 0; // преждевременный выход
		pos = (int)SendMessage(fwwnd, MES_ONNEWTHREAD, 0, 0);
		if( pos >= 0 ) break;
		Sleep(200);
	}

	//////////////////////////////////////////////////////////////////////////
	// название файла
	if( !SendFileName(fwwnd, cmdl.outputfilename, pos) )
		return 0; // выход, лажа.

	//////////////////////////////////////////////////////////////////////////
	// читаем файл из stdin и создаём временный wav-файл
	if( !ReadAndCreateFile(tempfile) )
		return 5;
	DWORD len = CorrectHeader(tempfile);
	//////////////////////////////////////////////////////////////////////////
	// сообщаем длинну трэка: sec * 4 * 44100
	if( !MySendMessage(fwwnd, MES_SENDLENGTH, pos, len) )
	{
		DeleteFile(tempfile);
		return 0;
	}
	if( len )
	{
		UINT newpriority = (UINT)SendMessage(fwwnd, MES_GETPRIORITY, 0, 0);
		SetPriorityClass(GetCurrentProcess(), newpriority );

		if( !RunProcessing(tempfile, mode, fwwnd, pos) )
		{
			DeleteFile(tempfile);
			return 0; // пытаемся безболезненно свалить :D
		}
	}
	DeleteFile(tempfile);
	if( !TrimFile(cmdl.outputfilename, pos) )
		return 6;

	return 0;
}