Ejemplo n.º 1
0
bool t_strConverter::C2W(const char *p_pSrc, int p_iSrcLen, wchar_t *p_pDst, int &p_iDstLen, int p_iEncodingType)
{
	switch( p_iEncodingType )
	{
	case -1:
	case ec_ucs2:
		{
			int nCopyLen = (int)(p_iSrcLen / sizeof(wchar_t)) < (int)(p_iDstLen - 1) ? p_iSrcLen / sizeof(wchar_t) : p_iDstLen - 1;
			wcsncpy_s(p_pDst, p_iDstLen, (wchar_t *)p_pSrc, nCopyLen);
			p_iDstLen = wcslen(p_pDst) * sizeof(wchar_t);
		}
		break;
	case ec_gbk:
		{
			p_iDstLen = ::MultiByteToWideChar(936, 0, p_pSrc, p_iSrcLen, p_pDst, p_iDstLen);
		}
		break;
	case ec_utf_8:
		{
			p_iDstLen = ::MultiByteToWideChar(CP_UTF8, 0, p_pSrc, p_iSrcLen, p_pDst, p_iDstLen);
		}
		break;
	case ec_ucs4:
		{
			U2W(p_pSrc, p_iSrcLen, p_pDst, p_iDstLen);
		}
		break;
	default:
		break;
	}

	return true;
}
Ejemplo n.º 2
0
static void node_emergency_shutdown(void *dummy) {
    DWORD result = MessageBox(NULL, L"Oh my, oh my. The backend decided to be very naughty, so looks like I have to crash.\n\nClick Yes to open troubleshooting instructions and reveal the log file.", L"LiveReload Crash", MB_YESNO | MB_ICONERROR);
    if (result == IDYES) {
        ShellExecute(NULL, L"explore", U2W(os_log_path), NULL, NULL, SW_SHOWNORMAL);
        ShellExecute(NULL, L"open", L"http://help.livereload.com/kb/troubleshooting/livereload-has-crashed-on-windows", NULL, NULL, SW_SHOWNORMAL);
    }
    ExitProcess(1);
}
Ejemplo n.º 3
0
void do_listen(fsmonitor_t *monitor) {
  HANDLE hChange = FindFirstChangeNotification(U2W(monitor->path), TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES);
  assert(hChange != INVALID_HANDLE_VALUE);
  printf("Listening to changes in %s\n", monitor->path);
  while (TRUE) {
    DWORD status = WaitForMultipleObjects(1, &hChange, FALSE, INFINITE);
    if (status == WAIT_OBJECT_0) {
      printf("Detected change in %s\n", monitor->path);
      invoke_on_main_thread((INVOKE_LATER_FUNC) fsmonitor_did_detect_change, monitor);
      DWORD result = FindNextChangeNotification(hChange);
      assert(result);
    } else {
      assert(!"WaitForMultipleObjects returned error");
    }
  }
}
Ejemplo n.º 4
0
// The following code is based off of KB190351
static void node_launch() {
    HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr;
    BOOL fSuccess;

    SECURITY_ATTRIBUTES saAttr;
    saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
    saAttr.bInheritHandle = TRUE;
    saAttr.lpSecurityDescriptor = NULL;

    fSuccess = CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0);
    assert(fSuccess);
    // make a non-inheritable duplicate and close the original (otherwise it gets inherited and we wouldn't be able to close it)
    fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, GetCurrentProcess(), &node_stdin_fd, 0, FALSE, DUPLICATE_SAME_ACCESS);
    assert(fSuccess);
    CloseHandle(hChildStdinWr);

    fSuccess = CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0);
    assert(fSuccess);
    fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, GetCurrentProcess(), &node_stdout_fd, 0, FALSE, DUPLICATE_SAME_ACCESS);
    assert(fSuccess);
    CloseHandle(hChildStdoutRd);

    STARTUPINFO siStartInfo;
    ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
    siStartInfo.cb = sizeof(STARTUPINFO);
    siStartInfo.dwFlags     = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    siStartInfo.hStdInput   = hChildStdinRd;
    siStartInfo.hStdOutput  = hChildStdoutWr;
    siStartInfo.hStdError   = GetStdHandle(STD_ERROR_HANDLE);
    siStartInfo.wShowWindow = SW_HIDE;

    char *cmd_line = str_printf("\"%s\" \"%s\"", os_bundled_node_path, node_bundled_backend_js);
    wchar_t *pszCmdLine = U2W(cmd_line);
    free(cmd_line);

    PROCESS_INFORMATION piProcInfo;
    fSuccess = CreateProcess(NULL, pszCmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo);
    assert(fSuccess);

    CloseHandle(piProcInfo.hThread);
    node_process = piProcInfo.hProcess;
    // piProcInfo.dwProcessId;

    // if we don't close these, ReadFile won't signal end-of-file (and will hang forever)
    CloseHandle(hChildStdinRd);
    CloseHandle(hChildStdoutWr);
}
Ejemplo n.º 5
0
void conserveField(struct Wtype *field, struct RUNPARAMS *param, struct PART *star, REAL dx, REAL aexp, REAL mstar){
// ----------------------------------------------------------//
/// compute the conservations equations after a star is created
// ----------------------------------------------------------//

	REAL drho = mstar / POW(dx,3.);
	struct Utype U;
	struct Wtype W;

	memcpy(&W,field,sizeof(struct Wtype));

	W2U(&W, &U);

//	density
	U.d    -= drho;

#ifdef WRADHYD
	REAL xion=W.dX/W.d;
	U.dX = U.d*xion;
#endif

//	momentum
	U.du -= star->vx * drho;
	U.dv -= star->vy * drho;
	U.dw -= star->vz * drho;

//	internal energy

#ifdef DUAL_E
	U.eint=U.eint*(1.-drho/W.d); // assuming T and x remain constant
#endif

	U2W(&U, &W);

//	total energy
	getE(&(W));
	W.a=SQRT(GAMMA*W.p/W.d);
	W.p=FMAX(W.p,PMIN);
	memcpy(field,&W,sizeof(struct Wtype));

	if(isnan(U.du)){
	  printf("drho=%e vx=%e\n",drho,star->vx);
	}

}
Ejemplo n.º 6
0
void kineticFeedback_simple(struct RUNPARAMS *param, struct CELL *cell,struct PART *curp, REAL aexp, int level, REAL E){

  REAL mtot_feedback = curp->mass* param->sn->ejecta_proportion;
  curp->mass -= mtot_feedback;

  struct OCT* oct = cell2oct(cell);
  int i;
  for(i=0;i<8;i++){
    struct CELL* curcell = &oct->cell[i];
    REAL dv = POW(0.5,3*level);// curent volume

    REAL dir_x[]={-1., 1.,-1., 1.,-1., 1.,-1., 1.};// diagonal projection
    REAL dir_y[]={-1.,-1., 1., 1.,-1.,-1., 1., 1.};
    REAL dir_z[]={-1.,-1.,-1.,-1., 1., 1., 1., 1.};

    REAL E_e = E/8.;
    REAL m_e = mtot_feedback/8.;
    REAL d_e = m_e/dv; // ejecta density

    REAL v_e = SQRT(2.*E_e/curcell->field.d);

    curcell->field.d += m_e/dv;
    curcell->field.u += v_e*dir_x[i]/SQRT(3.);
    curcell->field.v += v_e*dir_y[i]/SQRT(3.);
    curcell->field.w += v_e*dir_z[i]/SQRT(3.);

    //Energy conservation
#ifdef DUAL_E
    struct Utype U; // conservative field structure
    W2U(&cell->field, &U); // primitive to conservative
    U.eint*=1.+d_e/cell->field.d; // compute new internal energy
    U2W(&U, &cell->field); // back to primitive
#else
    cell->field.p*=1.+d_e/cell->field.d; // compute new internal energy
#endif
    getE(&curcell->field); //compute new total energy
    curcell->field.p=FMAX(curcell->field.p,PMIN);
    curcell->field.a=SQRT(GAMMA*curcell->field.p/curcell->field.d); // compute new sound speed
  }
}
Ejemplo n.º 7
0
void MainWnd_OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem) {
    if (lpDrawItem->itemID == -1)
        return;
    RECT rect = lpDrawItem->rcItem;
    project_t *project = project_get(lpDrawItem->itemID);
    WCHAR *name = U2W(project_name(project));
    HFONT hOldFont;

    // http://www.codeproject.com/KB/combobox/TransListBox.aspx
    switch (lpDrawItem->itemAction) {
        case ODA_SELECT:
        case ODA_DRAWENTIRE:
            if (lpDrawItem->itemState & ODS_SELECTED) {
                DrawState(lpDrawItem->hDC, NULL, NULL, (LPARAM)g_hListBoxSelectionBgBitmap, 0, rect.left, rect.top, 0, 0, DST_BITMAP);
            } else {
                RECT parentRect = rect;
                MapWindowPoints(g_hProjectListView, g_hMainWindow, (LPPOINT)&parentRect, 2);

                HDC hBitmapDC = CreateCompatibleDC(lpDrawItem->hDC);
                HBITMAP hOldBitmap = SelectBitmap(hBitmapDC, g_hMainWindowBgBitmap);
                BitBlt(lpDrawItem->hDC, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
                    hBitmapDC, parentRect.left, parentRect.top, SRCCOPY);
                SelectBitmap(hBitmapDC, hOldBitmap);
                DeleteDC(hBitmapDC);
            }
            DrawState(lpDrawItem->hDC, NULL, NULL, (LPARAM)g_hProjectIcon, 0, rect.left + 18, rect.top + 2, 0, 0, DST_ICON);
            SetTextAlign(lpDrawItem->hDC, TA_TOP | TA_LEFT);
            hOldFont = SelectFont(lpDrawItem->hDC, g_hNormalFont12);
            if (lpDrawItem->itemState & ODS_SELECTED) {
                SetTextColor(lpDrawItem->hDC, RGB(0xFF, 0xFF, 0xFF));
            } else {
                SetTextColor(lpDrawItem->hDC, RGB(0x00, 0x00, 0x00));
            }
            TextOut(lpDrawItem->hDC, rect.left + 39, rect.top + 1, name, wcslen(name));
            SelectFont(lpDrawItem->hDC, hOldFont);
    }
}
Ejemplo n.º 8
0
int kineticFeedback_mixt(struct RUNPARAMS *param, struct CELL *cell,struct PART *curp, REAL aexp, int level, REAL E, REAL dt){
// ----------------------------------------------------------//
/// Inject an energy "E" in all cells of the oct contening
/// the cell "cell" on kinetic form, radially to the center
/// of the oct and uniformly in all cells
// ----------------------------------------------------------//

  //REAL mtot_feedback = curp->mass* param->sn->ejecta_proportion;
  //printf("injecting_old m=%e, e=%e\t",curp->mass* param->sn->ejecta_proportion,E);

  REAL mtot_feedback = get_mass(param,curp,aexp,dt);

  if (mtot_feedback==0){
    printf("WARNING null mass in kinetic feedback!\n");
    return 1;
  }

  printf("injecting_new m=%e, e=%e\n",mtot_feedback ,E);

  int i;
{
//#define LOAD_FACTOR
#ifdef LOAD_FACTOR

  REAL load_factor=10;
  REAL local_rho_min=FLT_MAX;

  for(i=0;i<8;i++){
    struct OCT* oct = cell2oct(cell);
    struct CELL* curcell = &oct->cell[i];
    local_rho_min = FMIN(curcell->field.d,local_rho_min);
  }

  REAL lf = FMIN(load_factor*curp->mass,local_rho_min);
  mtot_feedback += lf;

  for(i=0;i<8;i++){
    struct OCT* oct = cell2oct(cell);
    struct CELL* curcell = &oct->cell[i];
    curcell->field.d -= lf/8.;
  }
#endif // LOAD_FACTOR
}

  for(i=0;i<8;i++){
    struct OCT* oct = cell2oct(cell);
    struct CELL* curcell = &oct->cell[i];
    REAL dv = POW(0.5,3*level);// curent volume

    REAL dir_x[]={-1., 1.,-1., 1.,-1., 1.,-1., 1.};// diagonal projection
    REAL dir_y[]={-1.,-1., 1., 1.,-1.,-1., 1., 1.};
    REAL dir_z[]={-1.,-1.,-1.,-1., 1., 1., 1., 1.};

    REAL fact = 1.0;

    REAL m_e = mtot_feedback/8.;
    REAL d_e = m_e/dv; // ejecta density
//--------------------------------------------------------------------------//

    // kinetic energy injection
    REAL E_e = E/8. *fact;
    REAL v_e = SQRT(2.*E_e/curcell->field.d);

    //printf("field.d=%e\n",curcell->field.d);
    REAL sqrt3 = SQRT(3.);
    curcell->field.u += v_e*dir_x[i]/sqrt3;
    curcell->field.v += v_e*dir_y[i]/sqrt3;
    curcell->field.w += v_e*dir_z[i]/sqrt3;
//--------------------------------------------------------------------------//
/*
    // momentum injection
    E_e = E/8. *(1.-fact) ; // uniform distribution
    v_e = SQRT(2.*E_e/d_e);// ejecta velocity / particle

    REAL vxe = curp->vx + v_e*dir_x[i]/sqrt3; // ejecta velocity /grid
    REAL vye = curp->vy + v_e*dir_y[i]/sqrt3;
    REAL vze = curp->vz + v_e*dir_z[i]/sqrt3;

    REAL d_i = curcell->field.d; // initial density
    REAL vxi = curcell->field.u; // initial velocity
    REAL vyi = curcell->field.v;
    REAL vzi = curcell->field.w;

    curcell->field.u = (vxi*d_i + vxe*d_e)/(d_i+d_e); //new velocity
    curcell->field.v = (vyi*d_i + vye*d_e)/(d_i+d_e);
    curcell->field.w = (vzi*d_i + vze*d_e)/(d_i+d_e);
*/
//--------------------------------------------------------------------------//

    // mass conservation
    curp->mass       -= m_e;
    curcell->field.d += d_e; //new density

    //Energy conservation
#ifdef DUAL_E
    struct Utype U; // conservative field structure
    W2U(&curcell->field, &U); // primitive to conservative
    U.eint*=1.+d_e/curcell->field.d; // compute new internal energy
    U2W(&U, &curcell->field); // back to primitive
#else
    curcell->field.p*=1.+d_e/curcell->field.d; // compute new internal energy
#endif

    getE(&curcell->field); //compute new total energy
    curcell->field.p=FMAX(curcell->field.p,PMIN);
    curcell->field.a=SQRT(GAMMA*curcell->field.p/curcell->field.d); // compute new sound speed
  }
  return 0;
}
Ejemplo n.º 9
0
void kineticFeedback_impulsion(struct RUNPARAMS *param, struct CELL *cell,struct PART *curp, REAL aexp, int level, REAL E){
// ----------------------------------------------------------//
/// Inject an energy "E" in all cells of the oct contening
/// the cell "cell" on kinetic form, radially to the center
/// of the oct and uniformly in all cells
// ----------------------------------------------------------//

  REAL mtot_feedback = curp->mass* param->sn->ejecta_proportion;
  curp->mass -= mtot_feedback;
  struct OCT* oct = cell2oct(cell);

  int i;
//#define LOAD_FACTOR
#ifdef LOAD_FACTOR

  REAL load_factor=10;

  REAL local_rho_min=FLT_MAX;

  for(i=0;i<8;i++){
    struct CELL* curcell = &oct->cell[i];
    local_rho_min = FMIN(curcell->field.d,local_rho_min);
  }

  REAL lf = FMIN(load_factor*curp->mass,local_rho_min);

  mtot_feedback += lf;
  for(i=0;i<8;i++){
    struct CELL* curcell = &oct->cell[i];
    curcell->field.d -= lf/8.;
  }
#endif // LOAD_FACTOR

  for(i=0;i<8;i++){
    struct CELL* curcell = &oct->cell[i];
    REAL dv = POW(0.5,3*level);// curent volume

    REAL dir_x[]={-1., 1.,-1., 1.,-1., 1.,-1., 1.};// diagonal projection
    REAL dir_y[]={-1.,-1., 1., 1.,-1.,-1., 1., 1.};
    REAL dir_z[]={-1.,-1.,-1.,-1., 1., 1., 1., 1.};

    REAL E_e = E/8.; // uniform distribution
    REAL m_e = mtot_feedback/8.;

    REAL d_e = m_e/dv; // ejecta density
    REAL v_e = SQRT(2.*E_e/d_e);// ejecta velocity / particle
    REAL vxe = curp->vx + v_e*dir_x[i]/SQRT(3.); // ejecta velocity /grid
    REAL vye = curp->vy + v_e*dir_y[i]/SQRT(3.);
    REAL vze = curp->vz + v_e*dir_z[i]/SQRT(3.);

    REAL d_i = curcell->field.d; // initial density
    REAL vxi = curcell->field.u; // initial velocity
    REAL vyi = curcell->field.v;
    REAL vzi = curcell->field.w;

    curcell->field.d += d_e; //new density
    curcell->field.u = (vxi*d_i + vxe*d_e)/(d_i+d_e); //new velocity
    curcell->field.v = (vyi*d_i + vye*d_e)/(d_i+d_e);
    curcell->field.w = (vzi*d_i + vze*d_e)/(d_i+d_e);


    //Energy conservation
#ifdef DUAL_E
    struct Utype U; // conservative field structure
    W2U(&curcell->field, &U); // primitive to conservative
    U.eint*=1.+d_e/curcell->field.d; // compute new internal energy
    U2W(&U, &curcell->field); // back to primitive
#else
    curcell->field.p*=1.+d_e/curcell->field.d; // compute new internal energy
#endif

    getE(&curcell->field); //compute new total energy
    curcell->field.p=FMAX(curcell->field.p,PMIN);
    curcell->field.a=SQRT(GAMMA*curcell->field.p/curcell->field.d); // compute new sound speed
  }
}
Ejemplo n.º 10
0
void kineticFeedback(struct RUNPARAMS *param, struct CELL *cell,struct PART *curp, REAL aexp, int level, REAL E){
// ----------------------------------------------------------//
/// Inject an energy "E" in all cells of the oct contening
/// the cell "cell" on kinetic form, radially to the center
/// of the oct and uniformly in all cells
// ----------------------------------------------------------//

#ifdef SNTEST
  //REAL msn = param->unitary_stars_test->mass * SOLAR_MASS /param->unit.unit_mass;
  //REAL mtot_feedback = msn * param->sn->ejecta_proportion;
  REAL mtot_feedback =0;
#else
  REAL mtot_feedback = curp->mass* param->sn->ejecta_proportion;
#endif // SNTEST

  struct OCT* oct = cell2oct(cell);

  int i;
  for(i=0;i<8;i++){
    struct CELL* curcell = &oct->cell[i];
    REAL dv = POW(2.,-3*level);// curent volume

    REAL e = E/8.; //uniform energy distribution

    REAL me = mtot_feedback/8.;

    if (mtot_feedback==0){
      // if there's no ejecta, we injecte the energy directly to the gas
      me = curcell->field.d * dv;
    }

    REAL rho_i = curcell->field.d; //initial density
    REAL rho_e = me/dv; // density ejecta

    REAL vxi = curcell->field.u; // initial velocity
    REAL vyi = curcell->field.v;
    REAL vzi = curcell->field.w;

    REAL ve = SQRT(2.*e/rho_e);// ejecta velocity

    REAL dir_x[]={-1., 1.,-1., 1.,-1., 1.,-1., 1.};// diagonal projection
    REAL dir_y[]={-1.,-1., 1., 1.,-1.,-1., 1., 1.};
    REAL dir_z[]={-1.,-1.,-1.,-1., 1., 1., 1., 1.};

#ifdef SNTEST
  REAL  x_src=param->unitary_stars_test->src_pos_x,
        y_src=param->unitary_stars_test->src_pos_y,
        z_src=param->unitary_stars_test->src_pos_z;

  if ( (x_src==0) && (y_src==0) && (z_src==0)) {
      REAL x[]={1., 0., 0., 0., 0., 0., 0., 0.};// diagonal projection
      REAL y[]={1., 0., 0., 0., 0., 0., 0., 0.};
      REAL z[]={1., 0., 0., 0., 0., 0., 0., 0.};
      int i;
      for (i=0;i<8; i++){
        dir_x[i]=x[i];
        dir_y[i]=y[i];
        dir_z[i]=z[i];
      }
    }
#endif // SNTEST


#ifdef PIC
    REAL vx0 = curp->vx;
    REAL vy0 = curp->vy;
    REAL vz0 = curp->vz;
#else
		REAL vx0 = curcell->field.u;
	  REAL vy0 = curcell->field.v;
	  REAL vz0 = curcell->field.w;
#endif // PIC

    REAL vxe = vx0 + ve*dir_x[i]/SQRT(3.); // projection on axis in the particle framework
    REAL vye = vy0 + ve*dir_y[i]/SQRT(3.);
    REAL vze = vz0 + ve*dir_z[i]/SQRT(3.);

#ifdef PIC
    if(mtot_feedback!=0)  curp->mass -= me; // new particle mass
#else
    curcell->field.d -= rho_e;
#endif // PIC

    if(mtot_feedback==0) {
      rho_i -= rho_e;
      //TODO verif if needed;
     // curcell->field.d -= rho_e;
    }

    curcell->field.u = (vxi*rho_i + vxe*rho_e)/(rho_i+rho_e); //new velocity
    curcell->field.v = (vyi*rho_i + vye*rho_e)/(rho_i+rho_e);
    curcell->field.w = (vzi*rho_i + vze*rho_e)/(rho_i+rho_e);

    curcell->field.d += rho_e; //new density

    //Energy conservation
#ifdef DUAL_E
    struct Utype U; // conservative field structure
    W2U(&curcell->field, &U); // primitive to conservative
    U.eint*=1.+rho_e/curcell->field.d; // compute new internal energy
    U2W(&U, &curcell->field); // back to primitive
#else
    curcell->field.p*=1.+rho_e/curcell->field.d; // compute new internal energy
#endif

    getE(&curcell->field); //compute new total energy
    curcell->field.p=FMAX(curcell->field.p,PMIN);
    curcell->field.a=SQRT(GAMMA*curcell->field.p/curcell->field.d); // compute new sound speed
  }
}
Ejemplo n.º 11
0
void C_app__failed_to_start(json_t *arg) {
    MessageBox(NULL, U2W(json_string_value(json_object_get(arg, "message"))), L"LiveReload failed to start", MB_OK | MB_ICONERROR);
    ExitProcess(1);
}