<commit_before>/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2010, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: test_plane_intersection.cpp 5686 2012-05-11 20:59:00Z gioia $
 */

#include <gtest/gtest.h>
#include <pcl/common/common.h>
#include <pcl/common/intersections.h>
#include <pcl/pcl_tests.h>

using namespace pcl;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST (PCL, lineWithLineIntersection)
{
  Eigen::Vector4f line_a;
  Eigen::Vector4f line_b;

  //case 1
  line_a.x() = 0.09100f;
  line_a.y() = 0.00200f;
  line_a.z() = 0.00300f;
  line_a.w() = 0.00400f;

  line_b.x() = 0.0157f;
  line_b.y() = 0.0333f;
  line_b.z() = 0.0678f;
  line_b.w() = 0.0995f;

  Eigen::Vector4f p1, p2;
  lineToLineSegment (line_a, line_b, p1, p2);

  Eigen::Vector4f point_case_1;
  bool result_case_1 = lineWithLineIntersection(line_a, line_b, point_case_1);

  double sqr_dist_case_1 = (p1 - p2).squaredNorm ();

  double default_sqr_eps = 1e-4;
  EXPECT_GT(sqr_dist_case_1, default_sqr_eps);
  Eigen::Vector4f zero(0.0f, 0.0f, 0.0f, 0.0f);
  EXPECT_EQ(point_case_1, zero);
  EXPECT_FALSE(result_case_1);

  pcl::ModelCoefficients line_a_mod;
  pcl::ModelCoefficients line_b_mod;

  std::vector<float> values_a_case_1;
  values_a_case_1.push_back(line_a.x());
  values_a_case_1.push_back(line_a.y());
  values_a_case_1.push_back(line_a.z());
  values_a_case_1.push_back(line_a.w());

  std::vector<float> values_b_case_1;
  values_b_case_1.push_back(line_b.x());
  values_b_case_1.push_back(line_b.y());
  values_b_case_1.push_back(line_b.z());
  values_b_case_1.push_back(line_b.w());

  line_a_mod.values = values_a_case_1;
  line_b_mod.values = values_b_case_1;

  Eigen::Vector4f point_mod_1;
  EXPECT_FALSE(lineWithLineIntersection(line_a_mod, line_b_mod, point_mod_1));
  EXPECT_EQ(result_case_1, lineWithLineIntersection(line_a_mod, line_b_mod, point_mod_1));
  EXPECT_EQ(point_mod_1, zero);

  //case 2
  line_a.x() = 0.09100f;
  line_a.y() = 0.00200f;
  line_a.z() = 0.00300f;
  line_a.w() = 0.00400f;

  line_b.x() = 0.00157f;
  line_b.y() = 0.00333f;
  line_b.z() = 0.00678f;
  line_b.w() = 0.00995f;

  lineToLineSegment (line_a, line_b, p1, p2);

  Eigen::Vector4f point_case_2;
  double sqr_eps_case_2 = 1e-1;
  bool result_case_2 = lineWithLineIntersection(line_a, line_b, point_case_2, sqr_eps_case_2);

  double sqr_dist_case_2 = (p1 - p2).squaredNorm ();
  EXPECT_LT(sqr_dist_case_2, sqr_eps_case_2);
  EXPECT_EQ(point_case_2, p1);
  EXPECT_TRUE(result_case_2);

  pcl::ModelCoefficients line_a_mod_2;
  pcl::ModelCoefficients line_b_mod_2;

  std::vector<float> values_a_case_2;
  values_a_case_2.push_back(0.1000f);
  values_a_case_2.push_back(0.2000f);
  values_a_case_2.push_back(0.3000f);
  values_a_case_2.push_back(0.4000f);

  std::vector<float> values_b_case_2;
  values_b_case_2.push_back(0.1001f);
  values_b_case_2.push_back(0.2001f);
  values_b_case_2.push_back(0.3001f);
  values_b_case_2.push_back(0.4001f);

  line_a_mod_2.values = values_a_case_2;
  line_b_mod_2.values = values_b_case_2;

  Eigen::Vector4f point_mod_2;
  Eigen::Vector4f point_mod_case_2;
  double sqr_mod_case_2 = 1e-1;

  Eigen::Vector4f coeff1 = Eigen::Vector4f::Map (&line_a_mod_2.values[0], line_a_mod_2.values.size ());
  Eigen::Vector4f coeff2 = Eigen::Vector4f::Map (&line_b_mod_2.values[0], line_b_mod_2.values.size ());

  Eigen::Vector4f p1_mod, p2_mod;
  lineToLineSegment (coeff1, coeff2, p1_mod, p2_mod);
  double sqr_mod_act_2 = (p1_mod - p2_mod).squaredNorm ();

  EXPECT_LT(sqr_mod_act_2, sqr_mod_case_2);
  EXPECT_EQ(lineWithLineIntersection (coeff1, coeff2, point_mod_case_2, sqr_mod_case_2),
                      lineWithLineIntersection(line_a_mod_2, line_b_mod_2, point_mod_2, sqr_mod_case_2));
  EXPECT_TRUE(lineWithLineIntersection(line_a_mod_2, line_b_mod_2, point_mod_2, sqr_mod_case_2));
  EXPECT_EQ(point_mod_2, point_mod_case_2);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST (PCL, planeWithPlaneIntersection)
{
  //Testing parallel planes
  const int k = 2;
  float x = 1.0f;
  float y = 2.0f;
  float z = 3.0f;
  float w = 4.0f;
  Eigen::Vector4f plane_a;
  plane_a.x() = x;
  plane_a.y() = y;
  plane_a.z() = z;
  plane_a.w() = w;

  EXPECT_EQ(1.0f, plane_a.x());
  EXPECT_EQ(2.0f, plane_a.y());
  EXPECT_EQ(3.0f, plane_a.z());
  EXPECT_EQ(4.0f, plane_a.w());

  Eigen::Vector4f plane_b;
  plane_b.x() = x;
  plane_b.y() = y;
  plane_b.z() = z;
  plane_b.w() = w + k;

  EXPECT_EQ(1.0f, plane_b.x());
  EXPECT_EQ(2.0f, plane_b.y());
  EXPECT_EQ(3.0f, plane_b.z());
  EXPECT_EQ(6.0f, plane_b.w());

  Eigen::VectorXf line;

  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 45));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 90));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 180));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 360));

  plane_b.x() = k * x;
  plane_b.y() = k * y;
  plane_b.z() = k * z;
  plane_b.w() = k * w;

  EXPECT_EQ(2.0f, plane_b.x());
  EXPECT_EQ(4.0f, plane_b.y());
  EXPECT_EQ(6.0f, plane_b.z());
  EXPECT_EQ(8.0f, plane_b.w());

  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 45));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 90));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 180));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 360));

  //overlapping planes
  plane_b.w() = w;
  EXPECT_EQ(4.0f, plane_b.w());

  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 45));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 90));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 180));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 360));

  //orthogonal planes
  plane_a.x() = 2.0f;
  plane_a.y() = 1.0f;
  plane_a.z() = -5.0f;
  plane_a.w() = 6.0f;
  EXPECT_EQ(2.0f, plane_a.x());
  EXPECT_EQ(1.0f, plane_a.y());
  EXPECT_EQ(-5.0f, plane_a.z());
  EXPECT_EQ(6.0f, plane_a.w());

  plane_b.x() = 2.0f;
  plane_b.y() = 1.0f;
  plane_b.z() = 1.0f;
  plane_b.w() = 7.0f;

  EXPECT_EQ(2.0f, plane_b.x());
  EXPECT_EQ(1.0f, plane_b.y());
  EXPECT_EQ(1.0f, plane_b.z());
  EXPECT_EQ(7.0f, plane_b.w());

  std::cout << std::endl;
  EXPECT_TRUE(planeWithPlaneIntersection(plane_a, plane_b, line, 0));

  //general planes
  plane_a.x() = 1.555f;
  plane_a.y() = 0.894f;
  plane_a.z() = 1.234f;
  plane_a.w() = 3.567f;

  plane_b.x() = 0.743f;
  plane_b.y() = 1.890f;
  plane_b.z() = 6.789f;
  plane_b.w() = 5.432f;

  std::cout << std::endl;
  EXPECT_TRUE(planeWithPlaneIntersection(plane_a, plane_b, line, 0));

}

//* ---[ */
int
main (int argc, char** argv)
{
  testing::InitGoogleTest (&argc, argv);
  return (RUN_ALL_TESTS ());
}
/* ]--- */

<commit_msg>fixed win32 compilation error on test_plane_intersection<commit_after>/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2010, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: test_plane_intersection.cpp 5686 2012-05-11 20:59:00Z gioia $
 */

#include <gtest/gtest.h>
#include <pcl/common/common.h>
#include <pcl/common/intersections.h>
#include <pcl/pcl_tests.h>

using namespace pcl;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST (PCL, lineWithLineIntersection)
{
  Eigen::Vector4f line_a;
  Eigen::Vector4f line_b;

  //case 1
  line_a.x() = 0.09100f;
  line_a.y() = 0.00200f;
  line_a.z() = 0.00300f;
  line_a.w() = 0.00400f;

  line_b.x() = 0.0157f;
  line_b.y() = 0.0333f;
  line_b.z() = 0.0678f;
  line_b.w() = 0.0995f;

  Eigen::Vector4f p1, p2;
  lineToLineSegment (line_a, line_b, p1, p2);

  Eigen::Vector4f point_case_1;
  bool result_case_1 = lineWithLineIntersection(line_a, line_b, point_case_1);

  double sqr_dist_case_1 = (p1 - p2).squaredNorm ();

  double default_sqr_eps = 1e-4;
  EXPECT_GT(sqr_dist_case_1, default_sqr_eps);
  Eigen::Vector4f zero(0.0f, 0.0f, 0.0f, 0.0f);

  EXPECT_EQ(point_case_1[0], zero[0]);
  EXPECT_EQ(point_case_1[1], zero[1]);
  EXPECT_EQ(point_case_1[2], zero[2]);
  EXPECT_EQ(point_case_1[3], zero[3]);

  EXPECT_FALSE(result_case_1);

  pcl::ModelCoefficients line_a_mod;
  pcl::ModelCoefficients line_b_mod;

  std::vector<float> values_a_case_1;
  values_a_case_1.push_back(line_a.x());
  values_a_case_1.push_back(line_a.y());
  values_a_case_1.push_back(line_a.z());
  values_a_case_1.push_back(line_a.w());

  std::vector<float> values_b_case_1;
  values_b_case_1.push_back(line_b.x());
  values_b_case_1.push_back(line_b.y());
  values_b_case_1.push_back(line_b.z());
  values_b_case_1.push_back(line_b.w());

  line_a_mod.values = values_a_case_1;
  line_b_mod.values = values_b_case_1;

  Eigen::Vector4f point_mod_1;
  EXPECT_FALSE(lineWithLineIntersection(line_a_mod, line_b_mod, point_mod_1));
  EXPECT_EQ(result_case_1, lineWithLineIntersection(line_a_mod, line_b_mod, point_mod_1));

  EXPECT_EQ(point_mod_1[0], zero[0]);
  EXPECT_EQ(point_mod_1[1], zero[1]);
  EXPECT_EQ(point_mod_1[2], zero[2]);
  EXPECT_EQ(point_mod_1[3], zero[3]);

  //case 2
  line_a.x() = 0.09100f;
  line_a.y() = 0.00200f;
  line_a.z() = 0.00300f;
  line_a.w() = 0.00400f;

  line_b.x() = 0.00157f;
  line_b.y() = 0.00333f;
  line_b.z() = 0.00678f;
  line_b.w() = 0.00995f;

  lineToLineSegment (line_a, line_b, p1, p2);

  Eigen::Vector4f point_case_2;
  double sqr_eps_case_2 = 1e-1;
  bool result_case_2 = lineWithLineIntersection(line_a, line_b, point_case_2, sqr_eps_case_2);

  double sqr_dist_case_2 = (p1 - p2).squaredNorm ();
  EXPECT_LT(sqr_dist_case_2, sqr_eps_case_2);

  EXPECT_EQ(point_case_2[0], p1[0]);
  EXPECT_EQ(point_case_2[1], p1[1]);
  EXPECT_EQ(point_case_2[2], p1[2]);
  EXPECT_EQ(point_case_2[3], p1[3]);

  EXPECT_TRUE(result_case_2);

  pcl::ModelCoefficients line_a_mod_2;
  pcl::ModelCoefficients line_b_mod_2;

  std::vector<float> values_a_case_2;
  values_a_case_2.push_back(0.1000f);
  values_a_case_2.push_back(0.2000f);
  values_a_case_2.push_back(0.3000f);
  values_a_case_2.push_back(0.4000f);

  std::vector<float> values_b_case_2;
  values_b_case_2.push_back(0.1001f);
  values_b_case_2.push_back(0.2001f);
  values_b_case_2.push_back(0.3001f);
  values_b_case_2.push_back(0.4001f);

  line_a_mod_2.values = values_a_case_2;
  line_b_mod_2.values = values_b_case_2;

  Eigen::Vector4f point_mod_2;
  Eigen::Vector4f point_mod_case_2;
  double sqr_mod_case_2 = 1e-1;

  Eigen::Vector4f coeff1 = Eigen::Vector4f::Map (&line_a_mod_2.values[0], line_a_mod_2.values.size ());
  Eigen::Vector4f coeff2 = Eigen::Vector4f::Map (&line_b_mod_2.values[0], line_b_mod_2.values.size ());

  Eigen::Vector4f p1_mod, p2_mod;
  lineToLineSegment (coeff1, coeff2, p1_mod, p2_mod);
  double sqr_mod_act_2 = (p1_mod - p2_mod).squaredNorm ();

  EXPECT_LT(sqr_mod_act_2, sqr_mod_case_2);
  EXPECT_EQ(lineWithLineIntersection (coeff1, coeff2, point_mod_case_2, sqr_mod_case_2),
                      lineWithLineIntersection(line_a_mod_2, line_b_mod_2, point_mod_2, sqr_mod_case_2));
  EXPECT_TRUE(lineWithLineIntersection(line_a_mod_2, line_b_mod_2, point_mod_2, sqr_mod_case_2));

  EXPECT_EQ(point_mod_2[0], point_mod_case_2[0]);
  EXPECT_EQ(point_mod_2[1], point_mod_case_2[1]);
  EXPECT_EQ(point_mod_2[2], point_mod_case_2[2]);
  EXPECT_EQ(point_mod_2[3], point_mod_case_2[3]);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST (PCL, planeWithPlaneIntersection)
{
  //Testing parallel planes
  const int k = 2;
  float x = 1.0f;
  float y = 2.0f;
  float z = 3.0f;
  float w = 4.0f;
  Eigen::Vector4f plane_a;
  plane_a.x() = x;
  plane_a.y() = y;
  plane_a.z() = z;
  plane_a.w() = w;

  EXPECT_EQ(1.0f, plane_a.x());
  EXPECT_EQ(2.0f, plane_a.y());
  EXPECT_EQ(3.0f, plane_a.z());
  EXPECT_EQ(4.0f, plane_a.w());

  Eigen::Vector4f plane_b;
  plane_b.x() = x;
  plane_b.y() = y;
  plane_b.z() = z;
  plane_b.w() = w + k;

  EXPECT_EQ(1.0f, plane_b.x());
  EXPECT_EQ(2.0f, plane_b.y());
  EXPECT_EQ(3.0f, plane_b.z());
  EXPECT_EQ(6.0f, plane_b.w());

  Eigen::VectorXf line;

  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 45));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 90));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 180));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 360));

  plane_b.x() = k * x;
  plane_b.y() = k * y;
  plane_b.z() = k * z;
  plane_b.w() = k * w;

  EXPECT_EQ(2.0f, plane_b.x());
  EXPECT_EQ(4.0f, plane_b.y());
  EXPECT_EQ(6.0f, plane_b.z());
  EXPECT_EQ(8.0f, plane_b.w());

  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 45));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 90));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 180));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 360));

  //overlapping planes
  plane_b.w() = w;
  EXPECT_EQ(4.0f, plane_b.w());

  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 45));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 90));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 180));
  std::cout << std::endl;
  EXPECT_FALSE(planeWithPlaneIntersection(plane_a, plane_b, line, 360));

  //orthogonal planes
  plane_a.x() = 2.0f;
  plane_a.y() = 1.0f;
  plane_a.z() = -5.0f;
  plane_a.w() = 6.0f;
  EXPECT_EQ(2.0f, plane_a.x());
  EXPECT_EQ(1.0f, plane_a.y());
  EXPECT_EQ(-5.0f, plane_a.z());
  EXPECT_EQ(6.0f, plane_a.w());

  plane_b.x() = 2.0f;
  plane_b.y() = 1.0f;
  plane_b.z() = 1.0f;
  plane_b.w() = 7.0f;

  EXPECT_EQ(2.0f, plane_b.x());
  EXPECT_EQ(1.0f, plane_b.y());
  EXPECT_EQ(1.0f, plane_b.z());
  EXPECT_EQ(7.0f, plane_b.w());

  std::cout << std::endl;
  EXPECT_TRUE(planeWithPlaneIntersection(plane_a, plane_b, line, 0));

  //general planes
  plane_a.x() = 1.555f;
  plane_a.y() = 0.894f;
  plane_a.z() = 1.234f;
  plane_a.w() = 3.567f;

  plane_b.x() = 0.743f;
  plane_b.y() = 1.890f;
  plane_b.z() = 6.789f;
  plane_b.w() = 5.432f;

  std::cout << std::endl;
  EXPECT_TRUE(planeWithPlaneIntersection(plane_a, plane_b, line, 0));

}

//* ---[ */
int
main (int argc, char** argv)
{
  testing::InitGoogleTest (&argc, argv);
  return (RUN_ALL_TESTS ());
}
/* ]--- */

<|endoftext|>


<commit_before>#include <iostream>
#include <cassert>

using namespace std;

namespace B64 {

static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";

static void encodeblock(const unsigned char* in, ostream* os, int len) {
  char out[4];
  out[0] = cb64[ in[0] >> 2 ];
  out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
  out[2] = (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
  out[3] = (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
  os->write(out, 4);
}

void b64encode(const char* data, const size_t size, ostream* out) {
  size_t cur = 0;
  while(cur < size) {
    int len = min(static_cast<size_t>(3), size - cur);
    encodeblock(reinterpret_cast<const unsigned char*>(&data[cur]), out, len);
    cur += len;
  }
}

static void decodeblock(const unsigned char* in, unsigned char* out) {
  out[0] = (unsigned char ) (in[0] << 2 | in[1] >> 4);
  out[1] = (unsigned char ) (in[1] << 4 | in[2] >> 2);
  out[2] = (unsigned char ) (((in[2] << 6) & 0xc0) | in[3]);
}

bool b64decode(const unsigned char* data, const size_t insize, char* out, const size_t outsize) {
  size_t cur = 0;
  size_t ocur = 0;
  unsigned char in[4];
  while(cur < insize) {
    assert(ocur < outsize);
    for (int i = 0; i < 4; ++i) {
      unsigned char v = data[cur];
      v = (unsigned char) ((v < 43 || v > 122) ? '\0' : cd64[ v - 43 ]);
      if (!v) {
        cerr << "B64 decode error at offset " << cur << " offending character: " << (int)data[cur] << endl;
        return false;
      }
      v = (unsigned char) ((v == '$') ? '\0' : v - 61);
      if (v) in[i] = v - 1; else in[i] = 0;
      ++cur;
    }
    decodeblock(in, reinterpret_cast<unsigned char*>(&out[ocur]));
    ocur += 3;
  }
  return true;
}

}

<commit_msg>fix buffer overrun<commit_after>#include <iostream>
#include <cassert>

using namespace std;

namespace B64 {

static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";

static void encodeblock(const unsigned char* in, ostream* os, int len) {
  char out[4];
  // cerr << len << endl;
  out[0] = cb64[ in[0] >> 2 ];
  out[1] = cb64[ ((in[0] & 0x03) << 4) | (len > 1 ? ((in[1] & 0xf0) >> 4) : static_cast<unsigned char>(0))];
  out[2] = (len > 2 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
  out[3] = (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
  os->write(out, 4);
}

void b64encode(const char* data, const size_t size, ostream* out) {
  size_t cur = 0;
  while(cur < size) {
    int len = min(static_cast<size_t>(3), size - cur);
    encodeblock(reinterpret_cast<const unsigned char*>(&data[cur]), out, len);
    cur += len;
  }
}

static void decodeblock(const unsigned char* in, unsigned char* out) {
  out[0] = (unsigned char ) (in[0] << 2 | in[1] >> 4);
  out[1] = (unsigned char ) (in[1] << 4 | in[2] >> 2);
  out[2] = (unsigned char ) (((in[2] << 6) & 0xc0) | in[3]);
}

bool b64decode(const unsigned char* data, const size_t insize, char* out, const size_t outsize) {
  size_t cur = 0;
  size_t ocur = 0;
  unsigned char in[4];
  while(cur < insize) {
    assert(ocur < outsize);
    for (int i = 0; i < 4; ++i) {
      unsigned char v = data[cur];
      v = (unsigned char) ((v < 43 || v > 122) ? '\0' : cd64[ v - 43 ]);
      if (!v) {
        cerr << "B64 decode error at offset " << cur << " offending character: " << (int)data[cur] << endl;
        return false;
      }
      v = (unsigned char) ((v == '$') ? '\0' : v - 61);
      if (v) in[i] = v - 1; else in[i] = 0;
      ++cur;
    }
    decodeblock(in, reinterpret_cast<unsigned char*>(&out[ocur]));
    ocur += 3;
  }
  return true;
}

}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: querycontroller.hxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: oj $ $Date: 2001-04-24 14:34:10 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef DBAUI_QUERYCONTROLLER_HXX
#define DBAUI_QUERYCONTROLLER_HXX

#ifndef DBAUI_JOINCONTROLLER_HXX
#include "JoinController.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
#include <com/sun/star/sdb/XSQLQueryComposer.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
#include <com/sun/star/util/XNumberFormatter.hpp>
#endif
#ifndef DBAUI_QUERYVIEW_HXX
#include "queryview.hxx"
#endif
#ifndef _UNDO_HXX
#include <svtools/undo.hxx>
#endif
#ifndef _CONNECTIVITY_PARSE_SQLITERATOR_HXX_
#include <connectivity/sqliterator.hxx>
#endif
#ifndef _CONNECTIVITY_SQLPARSE_HXX
#include <connectivity/sqlparse.hxx>
#endif
#ifndef _CONNECTIVITY_SQLNODE_HXX
#include <connectivity/sqlnode.hxx>
#endif
#ifndef _COM_SUN_STAR_IO_XOBJECTOUTPUTSTREAM_HPP_
#include <com/sun/star/io/XObjectOutputStream.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XOBJECTINPUTSTREAM_HPP_
#include <com/sun/star/io/XObjectInputStream.hpp>
#endif
#ifndef DBAUI_JOINTABLEVIEW_HXX
#include "JoinTableView.hxx"
#endif
#ifndef DBAUI_QUERYDESIGNCONTEXT_HXX
#include "ParseContext.hxx"
#endif

class VCLXWindow;
namespace dbaui
{
    class OQueryView;
    class OQueryContainerWindow;
    class OTableConnectionData;
    class OTableWindowData;
    class OAddTableDlg;
    class OTableFieldDesc;
    class OQueryTableWindow;
    class OQueryController : public OJoinController
    {
        ::std::vector<OTableFieldDesc*>         m_vTableFieldDesc;

        OQueryParseContext*                     m_pParseContext;
        ::connectivity::OSQLParser*             m_pSqlParser;   // to parse sql statements
        ::connectivity::OSQLParseTreeIterator*  m_pSqlIterator; // to iterate through them
        ::std::vector<sal_uInt32>               m_vColumnWidth;

        ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer >    m_xComposer;
        ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >    m_xFormatter;   // a number formatter working with the connection's NumberFormatsSupplier

        ::rtl::OUString m_sStatement;       // contains the sql statement
        ::rtl::OUString m_sUpdateCatalogName; // catalog for update data
        ::rtl::OUString m_sUpdateSchemaName;  // schema for update data
        ::rtl::OUString m_sUpdateTableName;   // table for update data
        ::rtl::OUString m_sName;            // name of the query

        OQueryContainerWindow*              m_pWindow;          // temporary window

        sal_Int32       m_nVisibleRows;     // which rows the selection browse should show
        sal_Int32       m_nSplitPos;        // the position of the splitter
        sal_Bool        m_bDesign;          // if design is true then we show the complete design otherwise only the text format
        sal_Bool        m_bDistinct;        // true when you want "select distinct" otherwise false
        sal_Bool        m_bViewAlias;       // show the alias row in the design view
        sal_Bool        m_bViewTable;       // show the table row in the design view
        sal_Bool        m_bViewFunction;    // show the function row in the design view
        sal_Bool        m_bEsacpeProcessing;// is true when we shouldn't parse the statement
        sal_Bool        m_bCreateView;      // set to true when we should create a view otherwise we create a normal query

        ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getElements() const;
        void askForNewName( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xElements,
                            sal_Bool _bSaveAs);
        // creates the querycomposer
        void setQueryComposer();
        void deleteIterator();
        void executeQuery();
        void doSaveAsDoc(sal_Bool _bSaveAs);

    protected:
        virtual String          getMenu() const;
        // all the features which should be handled by this class
        virtual void            AddSupportedFeatures();
        // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
        virtual FeatureState    GetState(sal_uInt16 nId);
        // execute a feature
        virtual void            Execute(sal_uInt16 nId);
        virtual ToolBox* CreateToolBox(Window* pParent);

        OQueryView* getQueryView() { return static_cast<OQueryView*>(m_pView); }
        virtual void createNewConnection(sal_Bool _bUI = sal_False);

    public:
        OQueryController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);

        ~OQueryController();
        ::std::vector<OTableFieldDesc*>*        getTableFieldDesc()         { return &m_vTableFieldDesc; }

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > getComponentWindow();

        virtual void    setModified(sal_Bool _bModified=sal_True);

        // should the statement be parsed by our own sql parser
        sal_Bool        isEsacpeProcessing()    const { return m_bEsacpeProcessing; }
        sal_Bool        isDesignMode()          const { return m_bDesign; }
        sal_Bool        isDistinct()            const { return m_bDistinct; }

        ::rtl::OUString getStatement()          const { return m_sStatement; }
        sal_Int32       getSplitPos()           const { return m_nSplitPos;}
        sal_Int32       getVisibleRows()        const { return m_nVisibleRows; }

        void            setDistinct(sal_Bool _bDistinct)        { m_bDistinct = _bDistinct;}
        void            setSplitPos(sal_Int32 _nSplitPos)       { m_nSplitPos = _nSplitPos;}
        void            setVisibleRows(sal_Int32 _nVisibleRows) { m_nVisibleRows = _nVisibleRows;}

        ::connectivity::OSQLParser*             getParser()         { return m_pSqlParser;  }
        ::connectivity::OSQLParseTreeIterator&  getParseIterator()  { return *m_pSqlIterator; }
        sal_uInt32 getColWidth(sal_uInt16 _nPos) const
        {
            return m_vColumnWidth.size() < _nPos ? m_vColumnWidth[_nPos] : sal_uInt32(0);
        }

        virtual sal_Bool Construct(Window* pParent);

        ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >    getNumberFormatter()const   { return m_xFormatter; }
        // XEventListener
        virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::beans::XPropertyChangeListener
        virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt);
        // ::com::sun::star::container::XContainerListener
        virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
        virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
        virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );

        // ::com::sun::star::frame::XController
        virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
        // ::com::sun::star::lang::XComponent
        virtual void        SAL_CALL disposing();

        // XServiceInfo
        virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
        // need by registration
        static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
                SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
        // lang::XInitialization
        virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

        //
        virtual void Load(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxIn);
        virtual void Save(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOut);

    protected:
        virtual OTableWindowData* createTableWindowData();
    };
}
#endif // DBAUI_QUERYCONTROLLER_HXX

<commit_msg>new method to fit the statement<commit_after>/*************************************************************************
 *
 *  $RCSfile: querycontroller.hxx,v $
 *
 *  $Revision: 1.14 $
 *
 *  last change: $Author: oj $ $Date: 2001-04-27 10:12:08 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the License); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an AS IS basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef DBAUI_QUERYCONTROLLER_HXX
#define DBAUI_QUERYCONTROLLER_HXX

#ifndef DBAUI_JOINCONTROLLER_HXX
#include "JoinController.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
#include <com/sun/star/sdbc/XConnection.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
#include <com/sun/star/sdb/XSQLQueryComposer.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
#include <com/sun/star/util/XNumberFormatter.hpp>
#endif
#ifndef DBAUI_QUERYVIEW_HXX
#include "queryview.hxx"
#endif
#ifndef _UNDO_HXX
#include <svtools/undo.hxx>
#endif
#ifndef _CONNECTIVITY_PARSE_SQLITERATOR_HXX_
#include <connectivity/sqliterator.hxx>
#endif
#ifndef _CONNECTIVITY_SQLPARSE_HXX
#include <connectivity/sqlparse.hxx>
#endif
#ifndef _CONNECTIVITY_SQLNODE_HXX
#include <connectivity/sqlnode.hxx>
#endif
#ifndef _COM_SUN_STAR_IO_XOBJECTOUTPUTSTREAM_HPP_
#include <com/sun/star/io/XObjectOutputStream.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XOBJECTINPUTSTREAM_HPP_
#include <com/sun/star/io/XObjectInputStream.hpp>
#endif
#ifndef DBAUI_JOINTABLEVIEW_HXX
#include "JoinTableView.hxx"
#endif
#ifndef DBAUI_QUERYDESIGNCONTEXT_HXX
#include "ParseContext.hxx"
#endif

class VCLXWindow;
namespace dbaui
{
    class OQueryView;
    class OQueryContainerWindow;
    class OTableConnectionData;
    class OTableWindowData;
    class OAddTableDlg;
    class OTableFieldDesc;
    class OQueryTableWindow;
    class OQueryController : public OJoinController
    {
        ::std::vector<OTableFieldDesc*>         m_vTableFieldDesc;

        OQueryParseContext*                     m_pParseContext;
        ::connectivity::OSQLParser*             m_pSqlParser;   // to parse sql statements
        ::connectivity::OSQLParseTreeIterator*  m_pSqlIterator; // to iterate through them
        ::std::vector<sal_uInt32>               m_vColumnWidth;

        ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer >    m_xComposer;
        ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >    m_xFormatter;   // a number formatter working with the connection's NumberFormatsSupplier

        ::rtl::OUString m_sStatement;       // contains the sql statement
        ::rtl::OUString m_sUpdateCatalogName; // catalog for update data
        ::rtl::OUString m_sUpdateSchemaName;  // schema for update data
        ::rtl::OUString m_sUpdateTableName;   // table for update data
        ::rtl::OUString m_sName;            // name of the query

        OQueryContainerWindow*              m_pWindow;          // temporary window

        sal_Int32       m_nVisibleRows;     // which rows the selection browse should show
        sal_Int32       m_nSplitPos;        // the position of the splitter
        sal_Bool        m_bDesign;          // if design is true then we show the complete design otherwise only the text format
        sal_Bool        m_bDistinct;        // true when you want "select distinct" otherwise false
        sal_Bool        m_bViewAlias;       // show the alias row in the design view
        sal_Bool        m_bViewTable;       // show the table row in the design view
        sal_Bool        m_bViewFunction;    // show the function row in the design view
        sal_Bool        m_bEsacpeProcessing;// is true when we shouldn't parse the statement
        sal_Bool        m_bCreateView;      // set to true when we should create a view otherwise we create a normal query

        ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getElements() const;
        void askForNewName( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xElements,
                            sal_Bool _bSaveAs);
        // creates the querycomposer
        void setQueryComposer();
        void deleteIterator();
        void executeQuery();
        void doSaveAsDoc(sal_Bool _bSaveAs);
        ::rtl::OUString translateStatement();

    protected:
        virtual String          getMenu() const;
        // all the features which should be handled by this class
        virtual void            AddSupportedFeatures();
        // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
        virtual FeatureState    GetState(sal_uInt16 nId);
        // execute a feature
        virtual void            Execute(sal_uInt16 nId);
        virtual ToolBox* CreateToolBox(Window* pParent);

        OQueryView* getQueryView() { return static_cast<OQueryView*>(m_pView); }
        virtual void createNewConnection(sal_Bool _bUI = sal_False);

    public:
        OQueryController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);

        ~OQueryController();
        ::std::vector<OTableFieldDesc*>*        getTableFieldDesc()         { return &m_vTableFieldDesc; }

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > getComponentWindow();

        virtual void    setModified(sal_Bool _bModified=sal_True);

        // should the statement be parsed by our own sql parser
        sal_Bool        isEsacpeProcessing()    const { return m_bEsacpeProcessing; }
        sal_Bool        isDesignMode()          const { return m_bDesign; }
        sal_Bool        isDistinct()            const { return m_bDistinct; }

        ::rtl::OUString getStatement()          const { return m_sStatement; }
        sal_Int32       getSplitPos()           const { return m_nSplitPos;}
        sal_Int32       getVisibleRows()        const { return m_nVisibleRows; }

        void            setDistinct(sal_Bool _bDistinct)        { m_bDistinct = _bDistinct;}
        void            setSplitPos(sal_Int32 _nSplitPos)       { m_nSplitPos = _nSplitPos;}
        void            setVisibleRows(sal_Int32 _nVisibleRows) { m_nVisibleRows = _nVisibleRows;}

        ::connectivity::OSQLParser*             getParser()         { return m_pSqlParser;  }
        ::connectivity::OSQLParseTreeIterator&  getParseIterator()  { return *m_pSqlIterator; }
        sal_uInt32 getColWidth(sal_uInt16 _nPos) const
        {
            return m_vColumnWidth.size() < _nPos ? m_vColumnWidth[_nPos] : sal_uInt32(0);
        }

        virtual sal_Bool Construct(Window* pParent);

        ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >    getNumberFormatter()const   { return m_xFormatter; }
        // XEventListener
        virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::beans::XPropertyChangeListener
        virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt);
        // ::com::sun::star::container::XContainerListener
        virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
        virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
        virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException );

        // ::com::sun::star::frame::XController
        virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
        // ::com::sun::star::lang::XComponent
        virtual void        SAL_CALL disposing();

        // XServiceInfo
        virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
        // need by registration
        static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
        static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
                SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
        // lang::XInitialization
        virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

        //
        virtual void Load(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxIn);
        virtual void Save(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOut);

    protected:
        virtual OTableWindowData* createTableWindowData();
    };
}
#endif // DBAUI_QUERYCONTROLLER_HXX

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: UserSettingsDlg.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 07:33:26 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"

#ifndef _DBU_REGHELPER_HXX_
#include "dbu_reghelper.hxx"
#endif
#ifndef _DBAUI_USERSETTINGSDLG_HXX
#include "UserSettingsDlg.hxx"
#endif
#ifndef DBAUI_USERADMINDLG_HXX
#include "UserAdminDlg.hxx"
#endif

using namespace dbaui;

extern "C" void SAL_CALL createRegistryInfo_OUserSettingsDialog()
{
    static OMultiInstanceAutoRegistration< OUserSettingsDialog > aAutoRegistration;
}

//.........................................................................
namespace dbaui
{
//.........................................................................

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;

//=========================================================================
//-------------------------------------------------------------------------
OUserSettingsDialog::OUserSettingsDialog(const Reference< XMultiServiceFactory >& _rxORB)
    :ODatabaseAdministrationDialog(_rxORB)
{
}
//-------------------------------------------------------------------------
Sequence<sal_Int8> SAL_CALL OUserSettingsDialog::getImplementationId(  ) throw(RuntimeException)
{
    static ::cppu::OImplementationId aId;
    return aId.getImplementationId();
}

//-------------------------------------------------------------------------
Reference< XInterface > SAL_CALL OUserSettingsDialog::Create(const Reference< XMultiServiceFactory >& _rxFactory)
{
    return *(new OUserSettingsDialog(_rxFactory));
}

//-------------------------------------------------------------------------
::rtl::OUString SAL_CALL OUserSettingsDialog::getImplementationName() throw(RuntimeException)
{
    return getImplementationName_Static();
}

//-------------------------------------------------------------------------
::rtl::OUString OUserSettingsDialog::getImplementationName_Static() throw(RuntimeException)
{
    return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.OUserSettingsDialog"));
}

//-------------------------------------------------------------------------
::comphelper::StringSequence SAL_CALL OUserSettingsDialog::getSupportedServiceNames() throw(RuntimeException)
{
    return getSupportedServiceNames_Static();
}

//-------------------------------------------------------------------------
::comphelper::StringSequence OUserSettingsDialog::getSupportedServiceNames_Static() throw(RuntimeException)
{
    ::comphelper::StringSequence aSupported(1);
    aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.UserAdministrationDialog"));
    return aSupported;
}

//-------------------------------------------------------------------------
Reference<XPropertySetInfo>  SAL_CALL OUserSettingsDialog::getPropertySetInfo() throw(RuntimeException)
{
    Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
    return xInfo;
}

//-------------------------------------------------------------------------
::cppu::IPropertyArrayHelper& OUserSettingsDialog::getInfoHelper()
{
    return *const_cast<OUserSettingsDialog*>(this)->getArrayHelper();
}

//------------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OUserSettingsDialog::createArrayHelper( ) const
{
    Sequence< Property > aProps;
    describeProperties(aProps);
    return new ::cppu::OPropertyArrayHelper(aProps);
}
//------------------------------------------------------------------------------
Dialog* OUserSettingsDialog::createDialog(Window* _pParent)
{
    OUserAdminDlg* pDlg = new OUserAdminDlg(_pParent, m_pDatasourceItems, m_xORB,m_aInitialSelection,m_xActiveConnection);
    return pDlg;
}

//.........................................................................
}   // namespace dbaui
//.........................................................................

<commit_msg>INTEGRATION: CWS changefileheader (1.5.258); FILE MERGED 2008/03/31 13:28:09 rt 1.5.258.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: UserSettingsDlg.cxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"

#ifndef _DBU_REGHELPER_HXX_
#include "dbu_reghelper.hxx"
#endif
#ifndef _DBAUI_USERSETTINGSDLG_HXX
#include "UserSettingsDlg.hxx"
#endif
#ifndef DBAUI_USERADMINDLG_HXX
#include "UserAdminDlg.hxx"
#endif

using namespace dbaui;

extern "C" void SAL_CALL createRegistryInfo_OUserSettingsDialog()
{
    static OMultiInstanceAutoRegistration< OUserSettingsDialog > aAutoRegistration;
}

//.........................................................................
namespace dbaui
{
//.........................................................................

    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;

//=========================================================================
//-------------------------------------------------------------------------
OUserSettingsDialog::OUserSettingsDialog(const Reference< XMultiServiceFactory >& _rxORB)
    :ODatabaseAdministrationDialog(_rxORB)
{
}
//-------------------------------------------------------------------------
Sequence<sal_Int8> SAL_CALL OUserSettingsDialog::getImplementationId(  ) throw(RuntimeException)
{
    static ::cppu::OImplementationId aId;
    return aId.getImplementationId();
}

//-------------------------------------------------------------------------
Reference< XInterface > SAL_CALL OUserSettingsDialog::Create(const Reference< XMultiServiceFactory >& _rxFactory)
{
    return *(new OUserSettingsDialog(_rxFactory));
}

//-------------------------------------------------------------------------
::rtl::OUString SAL_CALL OUserSettingsDialog::getImplementationName() throw(RuntimeException)
{
    return getImplementationName_Static();
}

//-------------------------------------------------------------------------
::rtl::OUString OUserSettingsDialog::getImplementationName_Static() throw(RuntimeException)
{
    return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.OUserSettingsDialog"));
}

//-------------------------------------------------------------------------
::comphelper::StringSequence SAL_CALL OUserSettingsDialog::getSupportedServiceNames() throw(RuntimeException)
{
    return getSupportedServiceNames_Static();
}

//-------------------------------------------------------------------------
::comphelper::StringSequence OUserSettingsDialog::getSupportedServiceNames_Static() throw(RuntimeException)
{
    ::comphelper::StringSequence aSupported(1);
    aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.UserAdministrationDialog"));
    return aSupported;
}

//-------------------------------------------------------------------------
Reference<XPropertySetInfo>  SAL_CALL OUserSettingsDialog::getPropertySetInfo() throw(RuntimeException)
{
    Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
    return xInfo;
}

//-------------------------------------------------------------------------
::cppu::IPropertyArrayHelper& OUserSettingsDialog::getInfoHelper()
{
    return *const_cast<OUserSettingsDialog*>(this)->getArrayHelper();
}

//------------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OUserSettingsDialog::createArrayHelper( ) const
{
    Sequence< Property > aProps;
    describeProperties(aProps);
    return new ::cppu::OPropertyArrayHelper(aProps);
}
//------------------------------------------------------------------------------
Dialog* OUserSettingsDialog::createDialog(Window* _pParent)
{
    OUserAdminDlg* pDlg = new OUserAdminDlg(_pParent, m_pDatasourceItems, m_xORB,m_aInitialSelection,m_xActiveConnection);
    return pDlg;
}

//.........................................................................
}   // namespace dbaui
//.........................................................................

<|endoftext|>


<commit_before>/*
| Yahtzee program                           |
| Written by Gabriel Simmer                 |
| I still don't know how to play yahtzee :P |
*/

#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctime>

using namespace std;

int main()
{
    SetConsoleTitle("Console Yahtzee");
    cout << "Text Yahtzee" << endl;
    cout << "By Gabriel Simmer" << endl;
    /*
    | Set console title, and display needed info |
    */
    srand(time(0)); //Seed random numbers from time
    int dice1;
    int dice2;
    int dice3;
    int dice4;
    int dice5;
    int catones;
    int cattwos;
    int catthrees;
    int catfours;
    int catfives;
    int catsixes;
    int cattotal;
    int catbonus;
    int allowedtoroll1 = 0;
    int allowedtoroll2 = 0;
    int allowedtoroll3 = 0;
    int allowedtoroll4 = 0;
    int allowedtoroll5 = 0;
    int loopbreak;
    int canUsecatones = 0;
    int canUsecattwos = 0;
    int canUsecatthrees = 0;
    int canUsecatfours = 0;
    int canUsecatfives = 0;
    int canUsecatsixes = 0;
    int catlocked1 = 0;
    int catlocked2 = 0;
    int catlocked3 = 0;
    int catlocked4 = 0;
    int catlocked5 = 0;
    int catlocked6 = 0;
    loopbreak = 0;
    string diceorcal; //Declares all variables needed
    while ( loopbreak != 1 ) {
    cout << " " << endl;
    cout << "Rolling for round." << endl;
    //Random numbers occur here
    dice1 = (1 + rand() % 6);
    cout << dice1;
    cout << " ";
    dice2 = (1 + rand() % 6);
    cout << dice2;
    cout << " ";
    dice3 = (1 + rand() % 6);
    cout << dice3;
    cout << " ";
    dice4 = (1 + rand() % 6);
    cout << dice4;
    dice5 = (1 + rand() % 6);
    cout << " ";
    cout << dice5 << endl ;
    int rerolldice;
        cout << "Use reroll to reroll a dice, or calculate to add up score (exit to exit)." << endl;
        cin >> diceorcal; //Make new random numbers if dice is chosen, 9 is exit, 8 is calculate score
        if ( diceorcal == "reroll" ){
            cout << "Dice to reroll: ";
            cin >> rerolldice;
            if ( rerolldice == 1 ) {
                    if ( allowedtoroll1 < 2 ) { //So that you can only roll twice
                        dice1 = (1 + rand() % 6 );
                        cout << "Dice One: ";
                        cout << dice1 << endl;
                        allowedtoroll1 = allowedtoroll1++;
                }
                else {
                    cout << "You can not roll that dice any more." << endl;
                    cout << " " << endl;
                }
            }
            if ( rerolldice == 2 ) {
                    if ( allowedtoroll2 < 2 ) {
                        dice2 = ( 1 + rand() % 6 );
                        cout << "Dice Two: ";
                        cout << dice2 << endl;
                        allowedtoroll2 = allowedtoroll2++;
                    }
                else {
                    cout << "You can not roll that dice any more" << endl;
                        cout << " " << endl;
                    }
                }
            if ( rerolldice == 3 ) {
                if ( allowedtoroll3 < 2 ) {
                    dice3 = ( 1 + rand() % 6 );
                    cout << "Dice Three: ";
                    cout << dice3 << endl;
                    allowedtoroll3 = allowedtoroll3++;
                }
                else {
                    cout << "You can not roll this dice any more" << endl;
                    cout << " " << endl;
                }
            }
            if ( rerolldice == 4 ) {
                if ( allowedtoroll4 < 2 ) {
                    dice4 = ( 1 + rand() % 6 );
                    cout << "Dice Four: ";
                    cout << dice4 << endl;
                }
            }
            if ( rerolldice == 5 ) {
                if ( allowedtoroll5 < 2 ) {
                    dice5 = ( 1 + rand() % 6 );
                    cout << "Dice Five: ";
                    cout << dice5 << endl;
                }
                else {
                    cout << "You can not roll this dice any more" << endl;
                    cout << " " << endl;
                }
            }
        }
        if ( diceorcal == "exit" ) {
            exit (EXIT_SUCCESS);
        }
        if ( diceorcal == "calculate") {
            loopbreak = 0; //Breaks the loop
            cout << "Current numbers rolled:" << endl;
            cout << dice1;
            cout << " ";
            cout << dice2;
            cout << " ";
            cout << dice3;
            cout << " ";
            cout << dice4;
            cout << " ";
            cout << dice5;
            cout << " " << endl;
            cout << "Score to which category?" << endl;
            cout << "aces, twos, thress, fours, fives, or sixes?" << endl;
            string aces = "aces";
            string twos = "twos";
            string threes = "threes";
            string fours = "fours";
            string fives = "fives";
            string sixes = "sixes";
            string scoresect;
            cin >> scoresect; //Choice strings
            if ( scoresect == aces ) { //Thanks to Mr. Last for the help with the catagories!
                if ( canUsecatones == 0 ){
                    catones=0;
                    if (dice1==1) catones++;
                    if (dice2==1) catones++;
                    if (dice3==1) catones++;
                    if (dice4==1) catones++;
                    if (dice5==1) catones++;
                    cout << catones << endl;
                    canUsecatones++;
                }
                else if ( canUsecatones > 0 ){
                    cout << "You've already used that catagory!" << endl;
                }
            }
            else if ( scoresect == twos ) {
                if ( canUsecattwos == 0 ){
                    cattwos=0;
                    if (dice1==2) cattwos=cattwos+2;
                    if (dice2==2) cattwos=cattwos+2;
                    if (dice3==2) cattwos=cattwos+2;
                    if (dice4==2) cattwos=cattwos+2;
                    if (dice5==2) cattwos=cattwos+2;
                    cout << cattwos << endl;
                    canUsecattwos++;
                }
                else if ( canUsecattwos > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }
            if ( scoresect == threes ){
                if ( canUsecatthrees == 0 ){
                    catthrees=0;
                    if (dice1==3) catthrees=catthrees+3;
                    if (dice2==3) catthrees=catthrees+3;
                    if (dice3==3) catthrees=catthrees+3;
                    if (dice4==3) catthrees=catthrees+3;
                    if (dice5==3) catthrees=catthrees+3;
                    cout << catthrees << endl;
                    canUsecatthrees++;
                }
                else if ( canUsecatthrees > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }

            else if ( scoresect == fours ) {
                if ( canUsecatfours == 0 ){
                    catfours=0;
                    if (dice1==4) catfours=catfours+4;
                    if (dice2==4) catfours=catfours+4;
                    if (dice3==4) catfours=catfours+4;
                    if (dice4==4) catfours=catfours+4;
                    if (dice5==4) catfours=catfours+4;
                    cout << catfours << endl;
                    canUsecatfours++;
                }
                else if ( canUsecatfours > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }
            else if ( scoresect == fives ) {
                if ( canUsecatfives == 0 ){
                    catfives=0;
                    if (dice1==5) catfives=catfives+5;
                    if (dice2==5) catfives=catfives+5;
                    if (dice3==5) catfives=catfives+5;
                    if (dice4==5) catfives=catfives+5;
                    if (dice5==5) catfives=catfives+5;
                    cout << catfives << endl;
                    canUsecatfives++;
                }
                else if ( canUsecatfives > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }

            }
            else if ( scoresect == sixes ) {
                if ( canUsecatsixes == 0 ){
                    catsixes=0;
                    if (dice1==6) catsixes=catsixes+6;
                    if (dice2==6) catsixes=catsixes+6;
                    if (dice3==6) catsixes=catsixes+6;
                    if (dice4==6) catsixes=catsixes+6;
                    if (dice5==6) catsixes=catsixes+6;
                    cout << catsixes << endl;
                    canUsecatsixes++;
                }
            else if ( canUsecatsixes > 0 ){
                cout << "You've already used this catagory!" << endl;
                }
            }
            loopbreak=0;
        }
    }

    return 0;
}

<commit_msg>Update yahtzee.cpp<commit_after>/*
| Yahtzee program           |
| Written by Gabriel Simmer |
| Broke it - again!         |
*/

#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctime>

using namespace std;

int main()
{
    SetConsoleTitle("Console Yahtzee");
    cout << "Text Yahtzee" << endl;
    cout << "By Gabriel Simmer" << endl;
    /*
    | Set console title, and display needed info |
    */
    srand(time(0)); //Seed random numbers from time
    int dice1;
    int dice2;
    int dice3;
    int dice4;
    int dice5;
    int catones;
    int cattwos;
    int catthrees;
    int catfours;
    int catfives;
    int catsixes;
    int cattotal;
    int catbonus;
    int allowedtoroll1 = 0;
    int allowedtoroll2 = 0;
    int allowedtoroll3 = 0;
    int allowedtoroll4 = 0;
    int allowedtoroll5 = 0;
    int loopbreak;
    int canUsecatones = 0;
    int canUsecattwos = 0;
    int canUsecatthrees = 0;
    int canUsecatfours = 0;
    int canUsecatfives = 0;
    int canUsecatsixes = 0;
    int catlocked1 = 0;
    int catlocked2 = 0;
    int catlocked3 = 0;
    int catlocked4 = 0;
    int catlocked5 = 0;
    int catlocked6 = 0;
    int rerolloop = 0;
    loopbreak = 0;
    string aces = "aces";
    string twos = "twos";
    string threes = "threes";
    string fours = "fours";
    string fives = "fives";
    string sixes = "sixes";
    string scoresect;
    string diceorcal; //Declares all variables needed
    while ( loopbreak != 1 ) {
    cout << " " << endl;
    cout << "Rolling for round." << endl;
    //Random numbers occur here
    dice1 = (1 + rand() % 6);
    cout << dice1;
    cout << " ";
    dice2 = (1 + rand() % 6);
    cout << dice2;
    cout << " ";
    dice3 = (1 + rand() % 6);
    cout << dice3;
    cout << " ";
    dice4 = (1 + rand() % 6);
    cout << dice4;
    dice5 = (1 + rand() % 6);
    cout << " ";
    cout << dice5 << endl ;
    int rerolldice;
        cout << "Use reroll to reroll a dice, or calculate to add up score (exit to exit)." << endl;
        cin >> diceorcal; //Choice for reroll or calculate.
        if ( diceorcal == "reroll" ){
            while ( rerolloop != 1 ) {
            cout << "Dice to reroll (enter 9 to calculate): ";
            cin >> rerolldice;
            if ( rerolldice == 1 ) {
                    if ( allowedtoroll1 < 2 ) { //So that you can only roll twice
                        dice1 = (1 + rand() % 6 );
                        cout << "Dice One: ";
                        cout << dice1 << endl;
                        allowedtoroll1 = allowedtoroll1++;
                }
                else {
                    cout << "You can not roll that dice any more." << endl;
                    cout << " " << endl;
                }
            }
            if ( rerolldice == 2 ) {
                    if ( allowedtoroll2 < 2 ) {
                        dice2 = ( 1 + rand() % 6 );
                        cout << "Dice Two: ";
                        cout << dice2 << endl;
                        allowedtoroll2 = allowedtoroll2++;
                    }
                else {
                    cout << "You can not roll that dice any more" << endl;
                        cout << " " << endl;
                    }
                }
            if ( rerolldice == 3 ) {
                if ( allowedtoroll3 < 2 ) {
                    dice3 = ( 1 + rand() % 6 );
                    cout << "Dice Three: ";
                    cout << dice3 << endl;
                    allowedtoroll3 = allowedtoroll3++;
                }
                else {
                    cout << "You can not roll this dice any more" << endl;
                    cout << " " << endl;
                }
            }
            if ( rerolldice == 4 ) {
                if ( allowedtoroll4 < 2 ) {
                    dice4 = ( 1 + rand() % 6 );
                    cout << "Dice Four: ";
                    cout << dice4 << endl;
                }
            }
            if ( rerolldice == 5 ) {
                if ( allowedtoroll5 < 2 ) {
                    dice5 = ( 1 + rand() % 6 );
                    cout << "Dice Five: ";
                    cout << dice5 << endl;
                }
                else {
                    cout << "You can not roll this dice any more" << endl;
                    cout << " " << endl;
                    }
                }
            if ( rerolldice == 9 ){
            canUsecatones = 0;
            canUsecattwos = 0;
            canUsecatthrees = 0;
            canUsecatfours = 0;
            canUsecatfives = 0;
            canUsecatsixes = 0;
            rerolloop = 1;
            cout << "Current numbers rolled:" << endl;
            cout << dice1;
            cout << " ";
            cout << dice2;
            cout << " ";
            cout << dice3;
            cout << " ";
            cout << dice4;
            cout << " ";
            cout << dice5;
            cout << " " << endl;
            cout << "Score to which category?" << endl;
            cout << "aces, twos, thress, fours, fives, or sixes?" << endl;
            cin >> scoresect; //Choice strings
            if ( scoresect == aces ) { //Thanks to Mr. Last for the help with the catagories!
                if ( canUsecatones == 0 ){
                    catones=0;
                    if (dice1==1) catones++;
                    if (dice2==1) catones++;
                    if (dice3==1) catones++;
                    if (dice4==1) catones++;
                    if (dice5==1) catones++;
                    cout << catones << endl;
                    canUsecatones++;
                }
                else if ( canUsecatones > 0 ){
                    cout << "You've already used that catagory!" << endl;
                }
            }
            else if ( scoresect == twos ) {
                if ( canUsecattwos == 0 ){
                    cattwos=0;
                    if (dice1==2) cattwos=cattwos+2;
                    if (dice2==2) cattwos=cattwos+2;
                    if (dice3==2) cattwos=cattwos+2;
                    if (dice4==2) cattwos=cattwos+2;
                    if (dice5==2) cattwos=cattwos+2;
                    cout << cattwos << endl;
                    canUsecattwos++;
                }
                else if ( canUsecattwos > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }
            if ( scoresect == threes ){
                if ( canUsecatthrees == 0 ){
                    catthrees=0;
                    if (dice1==3) catthrees=catthrees+3;
                    if (dice2==3) catthrees=catthrees+3;
                    if (dice3==3) catthrees=catthrees+3;
                    if (dice4==3) catthrees=catthrees+3;
                    if (dice5==3) catthrees=catthrees+3;
                    cout << catthrees << endl;
                    canUsecatthrees++;
                }
                else if ( canUsecatthrees > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }

            else if ( scoresect == fours ) {
                if ( canUsecatfours == 0 ){
                    catfours=0;
                    if (dice1==4) catfours=catfours+4;
                    if (dice2==4) catfours=catfours+4;
                    if (dice3==4) catfours=catfours+4;
                    if (dice4==4) catfours=catfours+4;
                    if (dice5==4) catfours=catfours+4;
                    cout << catfours << endl;
                    canUsecatfours++;
                }
                else if ( canUsecatfours > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }
            else if ( scoresect == fives ) {
                if ( canUsecatfives == 0 ){
                    catfives=0;
                    if (dice1==5) catfives=catfives+5;
                    if (dice2==5) catfives=catfives+5;
                    if (dice3==5) catfives=catfives+5;
                    if (dice4==5) catfives=catfives+5;
                    if (dice5==5) catfives=catfives+5;
                    cout << catfives << endl;
                    canUsecatfives++;
                }
                else if ( canUsecatfives > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }

            }
            else if ( scoresect == sixes ) {
                if ( canUsecatsixes == 0 ){
                    catsixes=0;
                    if (dice1==6) catsixes=catsixes+6;
                    if (dice2==6) catsixes=catsixes+6;
                    if (dice3==6) catsixes=catsixes+6;
                    if (dice4==6) catsixes=catsixes+6;
                    if (dice5==6) catsixes=catsixes+6;
                    cout << catsixes << endl;
                    canUsecatsixes++;
                }
            else if ( canUsecatsixes > 0 ){
                cout << "You've already used this catagory!" << endl;
                }
            }
        }

    }
    rerolloop = 0;
}
        if ( diceorcal == "exit" ) {
            exit (EXIT_SUCCESS);
        }
        if ( diceorcal == "calculate" ) {
            cout << "Current numbers rolled:" << endl;
            cout << dice1;
            cout << " ";
            cout << dice2;
            cout << " ";
            cout << dice3;
            cout << " ";
            cout << dice4;
            cout << " ";
            cout << dice5;
            cout << " " << endl;
            cout << "Score to which category?" << endl;
            cout << "aces, twos, thress, fours, fives, or sixes?" << endl;
            cin >> scoresect; //Choice strings
            if ( scoresect == aces ) { //Thanks to Mr. Last for the help with the catagories!
                if ( canUsecatones == 0 ){
                    catones=0;
                    if (dice1==1) catones++;
                    if (dice2==1) catones++;
                    if (dice3==1) catones++;
                    if (dice4==1) catones++;
                    if (dice5==1) catones++;
                    cout << catones << endl;
                    canUsecatones++;
                }
                else if ( canUsecatones > 0 ){
                    cout << "You've already used that catagory!" << endl;
                }
            }
            else if ( scoresect == twos ) {
                if ( canUsecattwos == 0 ){
                    cattwos=0;
                    if (dice1==2) cattwos=cattwos+2;
                    if (dice2==2) cattwos=cattwos+2;
                    if (dice3==2) cattwos=cattwos+2;
                    if (dice4==2) cattwos=cattwos+2;
                    if (dice5==2) cattwos=cattwos+2;
                    cout << cattwos << endl;
                    canUsecattwos++;
                }
                else if ( canUsecattwos > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }
            if ( scoresect == threes ){
                if ( canUsecatthrees == 0 ){
                    catthrees=0;
                    if (dice1==3) catthrees=catthrees+3;
                    if (dice2==3) catthrees=catthrees+3;
                    if (dice3==3) catthrees=catthrees+3;
                    if (dice4==3) catthrees=catthrees+3;
                    if (dice5==3) catthrees=catthrees+3;
                    cout << catthrees << endl;
                    canUsecatthrees++;
                }
                else if ( canUsecatthrees > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }

            else if ( scoresect == fours ) {
                if ( canUsecatfours == 0 ){
                    catfours=0;
                    if (dice1==4) catfours=catfours+4;
                    if (dice2==4) catfours=catfours+4;
                    if (dice3==4) catfours=catfours+4;
                    if (dice4==4) catfours=catfours+4;
                    if (dice5==4) catfours=catfours+4;
                    cout << catfours << endl;
                    canUsecatfours++;
                }
                else if ( canUsecatfours > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }
            }
            else if ( scoresect == fives ) {
                if ( canUsecatfives == 0 ){
                    catfives=0;
                    if (dice1==5) catfives=catfives+5;
                    if (dice2==5) catfives=catfives+5;
                    if (dice3==5) catfives=catfives+5;
                    if (dice4==5) catfives=catfives+5;
                    if (dice5==5) catfives=catfives+5;
                    cout << catfives << endl;
                    canUsecatfives++;
                }
                else if ( canUsecatfives > 0 ){
                    cout << "You've already used this catagory!" << endl;
                }

            }
            else if ( scoresect == sixes ) {
                if ( canUsecatsixes == 0 ){
                    catsixes=0;
                    if (dice1==6) catsixes=catsixes+6;
                    if (dice2==6) catsixes=catsixes+6;
                    if (dice3==6) catsixes=catsixes+6;
                    if (dice4==6) catsixes=catsixes+6;
                    if (dice5==6) catsixes=catsixes+6;
                    cout << catsixes << endl;
                    canUsecatsixes++;
                }
            else if ( canUsecatsixes > 0 ){
                cout << "You've already used this catagory!" << endl;
                }
            }
            loopbreak=0;
        }
    }

    return 0;
}

<|endoftext|>


<commit_before>#define WIN32_LEAN_AND_MEAN

#include "Error.h"
#include "Path.h"

#include <Windows.h>
#include <stdio.h>
#include <MinHook.h>

WCHAR g_ModuleName[MAX_PATH];

//////////////////////////////////////////////////////////////////
//
// CreateFileW
//
//////////////////////////////////////////////////////////////////

// Pointer to original function
HANDLE (WINAPI *fpCreateFileW)(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);

HANDLE WINAPI CreateFileW_Detour(
  _In_      LPCTSTR lpFileName,
  _In_      DWORD dwDesiredAccess,
  _In_      DWORD dwShareMode,
  _In_opt_  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  _In_      DWORD dwCreationDisposition,
  _In_      DWORD dwFlagsAndAttributes,
  _In_opt_  HANDLE hTemplateFile)
{
	LPCWSTR NewPath = CanonizePath(lpFileName);
	if (NewPath == NULL)
	{
		SetLastError(ERROR_OUTOFMEMORY);
		return INVALID_HANDLE_VALUE;
	}
	HANDLE hFile = fpCreateFileW(NewPath, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
	if (NewPath != lpFileName)
		delete []NewPath;
	return hFile;
}

//////////////////////////////////////////////////////////////////
//
// GetFileAttributesW
//
//////////////////////////////////////////////////////////////////

// Pointer to original function
DWORD (WINAPI *fpGetFileAttributesW)(LPCWSTR lpFileName);

DWORD WINAPI GetFileAttributesW_Detour(
    __in LPCWSTR lpFileName)
{
	LPCWSTR NewPath = CanonizePath(lpFileName);
	if (NewPath == NULL)
	{
		SetLastError(ERROR_OUTOFMEMORY);
		return INVALID_FILE_ATTRIBUTES;
	}
	DWORD ret = fpGetFileAttributesW(NewPath);
	if (NewPath != lpFileName)
		delete []NewPath;
	return ret;
}

//////////////////////////////////////////////////////////////////
//
// CreateProcessW
//
//////////////////////////////////////////////////////////////////

// Pointer to original function
BOOL (WINAPI *fpCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation);

// Inject a DLL into the target process by creating a new thread at LoadLibrary.
// Waits for injected thread to finish and returns its exit code.
bool LoadLibraryInjection(HANDLE hProcess, LPCWSTR LibraryName)
{
	size_t LibraryNameSize = (wcslen(LibraryName) + 1) * sizeof(WCHAR);
	LPVOID RemoteLibraryName = (LPVOID)VirtualAllocEx(hProcess, NULL, LibraryNameSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
	if (RemoteLibraryName == NULL)
	{
		return false;
	}

	if (WriteProcessMemory(hProcess, (LPVOID)RemoteLibraryName, LibraryName, LibraryNameSize, NULL) == 0)
	{
		DWORD error = GetLastError();
		VirtualFreeEx(hProcess, RemoteLibraryName, 0, MEM_RELEASE); // free the memory we were going to use
		SetLastError(error);
		return false;
	}

	HANDLE hThread = CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryW, (LPVOID)RemoteLibraryName, 0, NULL);
	if (hThread == NULL)
	{
		DWORD error = GetLastError();
		VirtualFreeEx(hProcess, RemoteLibraryName, 0, MEM_RELEASE);
		SetLastError(error);
		return false;
	}

	// Wait for the thread to finish.
	WaitForSingleObject(hThread, INFINITE);

	// Lets see what it says...
	DWORD dwThreadExitCode;
	if (!GetExitCodeThread(hThread,  &dwThreadExitCode))
	{
		DWORD error = GetLastError();
		CloseHandle(hThread);
		SetLastError(error);
		return false;
	}

	// No need for this handle anymore, lets get rid of it.
	CloseHandle(hThread);

	// Lets clear up that memory we allocated earlier.
	VirtualFreeEx(hProcess, RemoteLibraryName, 0, MEM_RELEASE);

	if (dwThreadExitCode == 0) // LoadLibrary failed
	{
		hThread = CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)GetLastError, (LPVOID)NULL, 0, NULL);
		if (hThread == NULL)
		{
			return false;
		}

		// Get last error
		WaitForSingleObject(hThread, INFINITE);
		if (!GetExitCodeThread(hThread,  &dwThreadExitCode))
		{
			DWORD error = GetLastError();
			CloseHandle(hThread);
			SetLastError(error);
			return false;
		}

		SetLastError(dwThreadExitCode);
		return false;
	}

	return true;
}

BOOL WINAPI CreateProcessW_Detour(
    __in_opt    LPCWSTR lpApplicationName,
    __inout_opt LPWSTR lpCommandLine,
    __in_opt    LPSECURITY_ATTRIBUTES lpProcessAttributes,
    __in_opt    LPSECURITY_ATTRIBUTES lpThreadAttributes,
    __in        BOOL bInheritHandles,
    __in        DWORD dwCreationFlags,
    __in_opt    LPVOID lpEnvironment,
    __in_opt    LPCWSTR lpCurrentDirectory,
    __in        LPSTARTUPINFOW lpStartupInfo,
    __out       LPPROCESS_INFORMATION lpProcessInformation
    )
{
	PROCESS_INFORMATION pi;
	if (lpProcessInformation == NULL)
		lpProcessInformation = π

	// Start our new process with a suspended main thread
	BOOL CreateProcessResult = fpCreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);

	if (CreateProcessResult)
	{
		// Inject our DLL
		// This method returns only when injection thread returns.
		if (!LoadLibraryInjection(lpProcessInformation->hProcess, g_ModuleName))
		{
			PrintError(L"WARNING: Failed to inject DLL %s", g_ModuleName);
		}

		// Once the injection thread has returned it is safe to resume the main thread.
		ResumeThread(lpProcessInformation->hThread);
	}

	return CreateProcessResult;
}

//////////////////////////////////////////////////////////////////

BOOL Init(HINSTANCE hinstDLL)
{
	if (GetModuleFileName(hinstDLL, g_ModuleName, MAX_PATH) == 0)
		return FALSE;

    // Initialize MinHook
    if (MH_Initialize() != MH_OK)
		return FALSE;

    // Create hooks in disabled state
    if (MH_CreateHook(&CreateFileW, &CreateFileW_Detour, (LPVOID*)&fpCreateFileW) != MH_OK)
		return FALSE;
    if (MH_CreateHook(&CreateProcessW, &CreateProcessW_Detour, (LPVOID*)&fpCreateProcessW) != MH_OK)
		return FALSE;
    if (MH_CreateHook(&GetFileAttributesW, &GetFileAttributesW_Detour, (LPVOID*)&fpGetFileAttributesW) != MH_OK)
		return FALSE;

    // Enable the hooks
    if (MH_EnableHook(&CreateFileW) != MH_OK)
		return FALSE;
    if (MH_EnableHook(&CreateProcessW) != MH_OK)
		return FALSE;
    if (MH_EnableHook(&GetFileAttributesW) != MH_OK)
		return FALSE;

	return TRUE;
}

BOOL Uninit()
{
    // Disable hooks
    if (MH_DisableHook(&CreateFileW) != MH_OK)
		return FALSE;
    if (MH_DisableHook(&CreateProcessW) != MH_OK)
		return FALSE;
    if (MH_DisableHook(&GetFileAttributesW) != MH_OK)
		return FALSE;

    // Uninitialize MinHook
    if (MH_Uninitialize() != MH_OK)
		return FALSE;

	return TRUE;
}

BOOL WINAPI DllMain(
  _In_  HINSTANCE hinstDLL,
  _In_  DWORD fdwReason,
  _In_  LPVOID lpvReserved
)
{
	switch (fdwReason)
	{
	case DLL_PROCESS_ATTACH:
		return Init(hinstDLL);
	case DLL_PROCESS_DETACH:
		return Uninit();
	default:
		return TRUE;
	}
}
<commit_msg>Bugfix: Only resume thread if caller not requested CREATE_SUSPENDED<commit_after>#define WIN32_LEAN_AND_MEAN

#include "Error.h"
#include "Path.h"

#include <Windows.h>
#include <stdio.h>
#include <MinHook.h>

WCHAR g_ModuleName[MAX_PATH];

//////////////////////////////////////////////////////////////////
//
// CreateFileW
//
//////////////////////////////////////////////////////////////////

// Pointer to original function
HANDLE (WINAPI *fpCreateFileW)(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);

HANDLE WINAPI CreateFileW_Detour(
  _In_      LPCTSTR lpFileName,
  _In_      DWORD dwDesiredAccess,
  _In_      DWORD dwShareMode,
  _In_opt_  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  _In_      DWORD dwCreationDisposition,
  _In_      DWORD dwFlagsAndAttributes,
  _In_opt_  HANDLE hTemplateFile)
{
	LPCWSTR NewPath = CanonizePath(lpFileName);
	if (NewPath == NULL)
	{
		SetLastError(ERROR_OUTOFMEMORY);
		return INVALID_HANDLE_VALUE;
	}
	HANDLE hFile = fpCreateFileW(NewPath, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
	if (NewPath != lpFileName)
		delete []NewPath;
	return hFile;
}

//////////////////////////////////////////////////////////////////
//
// GetFileAttributesW
//
//////////////////////////////////////////////////////////////////

// Pointer to original function
DWORD (WINAPI *fpGetFileAttributesW)(LPCWSTR lpFileName);

DWORD WINAPI GetFileAttributesW_Detour(
    __in LPCWSTR lpFileName)
{
	LPCWSTR NewPath = CanonizePath(lpFileName);
	if (NewPath == NULL)
	{
		SetLastError(ERROR_OUTOFMEMORY);
		return INVALID_FILE_ATTRIBUTES;
	}
	DWORD ret = fpGetFileAttributesW(NewPath);
	if (NewPath != lpFileName)
		delete []NewPath;
	return ret;
}

//////////////////////////////////////////////////////////////////
//
// CreateProcessW
//
//////////////////////////////////////////////////////////////////

// Pointer to original function
BOOL (WINAPI *fpCreateProcessW)(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation);

// Inject a DLL into the target process by creating a new thread at LoadLibrary.
// Waits for injected thread to finish and returns its exit code.
bool LoadLibraryInjection(HANDLE hProcess, LPCWSTR LibraryName)
{
	size_t LibraryNameSize = (wcslen(LibraryName) + 1) * sizeof(WCHAR);
	LPVOID RemoteLibraryName = (LPVOID)VirtualAllocEx(hProcess, NULL, LibraryNameSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
	if (RemoteLibraryName == NULL)
	{
		return false;
	}

	if (WriteProcessMemory(hProcess, (LPVOID)RemoteLibraryName, LibraryName, LibraryNameSize, NULL) == 0)
	{
		DWORD error = GetLastError();
		VirtualFreeEx(hProcess, RemoteLibraryName, 0, MEM_RELEASE); // free the memory we were going to use
		SetLastError(error);
		return false;
	}

	HANDLE hThread = CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryW, (LPVOID)RemoteLibraryName, 0, NULL);
	if (hThread == NULL)
	{
		DWORD error = GetLastError();
		VirtualFreeEx(hProcess, RemoteLibraryName, 0, MEM_RELEASE);
		SetLastError(error);
		return false;
	}

	// Wait for the thread to finish.
	WaitForSingleObject(hThread, INFINITE);

	// Lets see what it says...
	DWORD dwThreadExitCode;
	if (!GetExitCodeThread(hThread,  &dwThreadExitCode))
	{
		DWORD error = GetLastError();
		CloseHandle(hThread);
		SetLastError(error);
		return false;
	}

	// No need for this handle anymore, lets get rid of it.
	CloseHandle(hThread);

	// Lets clear up that memory we allocated earlier.
	VirtualFreeEx(hProcess, RemoteLibraryName, 0, MEM_RELEASE);

	if (dwThreadExitCode == 0) // LoadLibrary failed
	{
		hThread = CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)GetLastError, (LPVOID)NULL, 0, NULL);
		if (hThread == NULL)
		{
			return false;
		}

		// Get last error
		WaitForSingleObject(hThread, INFINITE);
		if (!GetExitCodeThread(hThread,  &dwThreadExitCode))
		{
			DWORD error = GetLastError();
			CloseHandle(hThread);
			SetLastError(error);
			return false;
		}

		SetLastError(dwThreadExitCode);
		return false;
	}

	return true;
}

BOOL WINAPI CreateProcessW_Detour(
    __in_opt    LPCWSTR lpApplicationName,
    __inout_opt LPWSTR lpCommandLine,
    __in_opt    LPSECURITY_ATTRIBUTES lpProcessAttributes,
    __in_opt    LPSECURITY_ATTRIBUTES lpThreadAttributes,
    __in        BOOL bInheritHandles,
    __in        DWORD dwCreationFlags,
    __in_opt    LPVOID lpEnvironment,
    __in_opt    LPCWSTR lpCurrentDirectory,
    __in        LPSTARTUPINFOW lpStartupInfo,
    __out       LPPROCESS_INFORMATION lpProcessInformation
    )
{
	PROCESS_INFORMATION pi;
	if (lpProcessInformation == NULL)
		lpProcessInformation = π

	// Start our new process with a suspended main thread
	BOOL CreateProcessResult = fpCreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);

	if (CreateProcessResult)
	{
		// Inject our DLL
		// This method returns only when injection thread returns.
		if (!LoadLibraryInjection(lpProcessInformation->hProcess, g_ModuleName))
		{
			PrintError(L"WARNING: Failed to inject DLL %s", g_ModuleName);
		}

		// Once the injection thread has returned it is safe to resume the main thread,
		// but only if the caller hasn't requested CREATE_SUSPENDED themselves.
		if ((dwCreationFlags & CREATE_SUSPENDED) == 0)
			ResumeThread(lpProcessInformation->hThread);
	}

	return CreateProcessResult;
}

//////////////////////////////////////////////////////////////////

BOOL Init(HINSTANCE hinstDLL)
{
	if (GetModuleFileName(hinstDLL, g_ModuleName, MAX_PATH) == 0)
		return FALSE;

    // Initialize MinHook
    if (MH_Initialize() != MH_OK)
		return FALSE;

    // Create hooks in disabled state
    if (MH_CreateHook(&CreateFileW, &CreateFileW_Detour, (LPVOID*)&fpCreateFileW) != MH_OK)
		return FALSE;
    if (MH_CreateHook(&CreateProcessW, &CreateProcessW_Detour, (LPVOID*)&fpCreateProcessW) != MH_OK)
		return FALSE;
    if (MH_CreateHook(&GetFileAttributesW, &GetFileAttributesW_Detour, (LPVOID*)&fpGetFileAttributesW) != MH_OK)
		return FALSE;

    // Enable the hooks
    if (MH_EnableHook(&CreateFileW) != MH_OK)
		return FALSE;
    if (MH_EnableHook(&CreateProcessW) != MH_OK)
		return FALSE;
    if (MH_EnableHook(&GetFileAttributesW) != MH_OK)
		return FALSE;

	return TRUE;
}

BOOL Uninit()
{
    // Disable hooks
    if (MH_DisableHook(&CreateFileW) != MH_OK)
		return FALSE;
    if (MH_DisableHook(&CreateProcessW) != MH_OK)
		return FALSE;
    if (MH_DisableHook(&GetFileAttributesW) != MH_OK)
		return FALSE;

    // Uninitialize MinHook
    if (MH_Uninitialize() != MH_OK)
		return FALSE;

	return TRUE;
}

BOOL WINAPI DllMain(
  _In_  HINSTANCE hinstDLL,
  _In_  DWORD fdwReason,
  _In_  LPVOID lpvReserved
)
{
	switch (fdwReason)
	{
	case DLL_PROCESS_ATTACH:
		return Init(hinstDLL);
	case DLL_PROCESS_DETACH:
		return Uninit();
	default:
		return TRUE;
	}
}
<|endoftext|>


<commit_before>/**
 * \file SettingsFrame.cpp
 * \brief Main Settings Class
 */

#include "SettingsFrame.h"

BEGIN_EVENT_TABLE(SettingsFrame,BaseFrame)
    EVT_BUTTON(ID_OK,  SettingsFrame::OnOk)
    EVT_BUTTON(ID_CANCEL,  SettingsFrame::OnCancel)
END_EVENT_TABLE()

/**
   Constructor for the Main frame.
*/

SettingsFrame::SettingsFrame(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
: BaseFrame(parent, id, title, position, size, style) {
    deviceId = "Please select a device from the menu.";

    CreateGUIControls();

    SetTransparent(225);
}

/**
   Destructor for the Main form.
*/

SettingsFrame::~SettingsFrame() {
}

/**
   Creates all of the GUI controls on the main form.
*/

void SettingsFrame::CreateGUIControls() {

    // Set window properties and title bar
    SetTitle(wxT("Settings"));
    SetIcon(wxNullIcon);

    mainPanel = new wxPanel(this, wxID_ANY);
    mainSizer = new wxBoxSizer(wxVERTICAL);
    mainPanel->SetSizer(mainSizer);

    dbHost = new wxTextCtrl(mainPanel,-1,DB_HOST);
    dbName = new wxTextCtrl(mainPanel,-1,DB_NAME);
    dbUser = new wxTextCtrl(mainPanel,-1,DB_USER);
    dbPass = new wxTextCtrl(mainPanel,-1,DB_PASS);

    wxStaticText* db_host_label = new wxStaticText(mainPanel,-1,wxT("Database Hostname"));
    wxStaticText* db_name_label = new wxStaticText(mainPanel,-1,wxT("Database Name"));
    wxStaticText* db_user_label = new wxStaticText(mainPanel,-1,wxT("Database Username"));
    wxStaticText* db_pass_label = new wxStaticText(mainPanel,-1,wxT("Database Password"));

    wxButton* ok_button = new wxButton(mainPanel,ID_OK,wxT("Ok"));
    wxButton* cancel_button = new wxButton(mainPanel,ID_CANCEL,wxT("Cancel"));

    mainSizer->Add(db_host_label, 0);
    mainSizer->Add(dbHost,       0);
    mainSizer->Add(db_name_label, 0);
    mainSizer->Add(dbName,       0);
    mainSizer->Add(db_user_label, 0);
    mainSizer->Add(dbUser,       0);
    mainSizer->Add(db_pass_label, 0);
    mainSizer->Add(dbPass,       0);
    mainSizer->Add(ok_button,       0);
    mainSizer->Add(cancel_button,       0);

    Update();
}

void SettingsFrame::Update() {
}

void SettingsFrame::OnOk( wxCommandEvent& event ) {
    DB_HOST = dbHost->GetValue();
    DB_NAME = dbName->GetValue();
    DB_USER = dbUser->GetValue();
    DB_PASS = dbPass->GetValue();

    wxCloseEvent close_event;
    OnClose(close_event);
}

void SettingsFrame::OnCancel( wxCommandEvent& event ) {
    wxCloseEvent close_event;
    OnClose(close_event);
}

wxFrame* NewSettingsFrame() {
    return (wxFrame*)(new SettingsFrame(NULL));
}

<commit_msg>- reconnect to database on settings ok<commit_after>/**
 * \file SettingsFrame.cpp
 * \brief Main Settings Class
 */

#include "SettingsFrame.h"

BEGIN_EVENT_TABLE(SettingsFrame,BaseFrame)
    EVT_BUTTON(ID_OK,  SettingsFrame::OnOk)
    EVT_BUTTON(ID_CANCEL,  SettingsFrame::OnCancel)
END_EVENT_TABLE()

/**
   Constructor for the Main frame.
*/

SettingsFrame::SettingsFrame(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
: BaseFrame(parent, id, title, position, size, style) {
    deviceId = "Please select a device from the menu.";

    CreateGUIControls();

    SetTransparent(225);
}

/**
   Destructor for the Main form.
*/

SettingsFrame::~SettingsFrame() {
}

/**
   Creates all of the GUI controls on the main form.
*/

void SettingsFrame::CreateGUIControls() {

    // Set window properties and title bar
    SetTitle(wxT("Settings"));
    SetIcon(wxNullIcon);

    mainPanel = new wxPanel(this, wxID_ANY);
    mainSizer = new wxBoxSizer(wxVERTICAL);
    mainPanel->SetSizer(mainSizer);

    dbHost = new wxTextCtrl(mainPanel,-1,DB_HOST);
    dbName = new wxTextCtrl(mainPanel,-1,DB_NAME);
    dbUser = new wxTextCtrl(mainPanel,-1,DB_USER);
    dbPass = new wxTextCtrl(mainPanel,-1,DB_PASS);

    wxStaticText* db_host_label = new wxStaticText(mainPanel,-1,wxT("Database Hostname"));
    wxStaticText* db_name_label = new wxStaticText(mainPanel,-1,wxT("Database Name"));
    wxStaticText* db_user_label = new wxStaticText(mainPanel,-1,wxT("Database Username"));
    wxStaticText* db_pass_label = new wxStaticText(mainPanel,-1,wxT("Database Password"));

    wxButton* ok_button = new wxButton(mainPanel,ID_OK,wxT("Ok"));
    wxButton* cancel_button = new wxButton(mainPanel,ID_CANCEL,wxT("Cancel"));

    mainSizer->Add(db_host_label, 0);
    mainSizer->Add(dbHost,       0);
    mainSizer->Add(db_name_label, 0);
    mainSizer->Add(dbName,       0);
    mainSizer->Add(db_user_label, 0);
    mainSizer->Add(dbUser,       0);
    mainSizer->Add(db_pass_label, 0);
    mainSizer->Add(dbPass,       0);
    mainSizer->Add(ok_button,       0);
    mainSizer->Add(cancel_button,       0);

    Update();
}

void SettingsFrame::Update() {
}

void SettingsFrame::OnOk( wxCommandEvent& event ) {
    DB_HOST = dbHost->GetValue();
    DB_NAME = dbName->GetValue();
    DB_USER = dbUser->GetValue();
    DB_PASS = dbPass->GetValue();

    DB_connect();

    wxCloseEvent close_event;
    OnClose(close_event);
}

void SettingsFrame::OnCancel( wxCommandEvent& event ) {
    wxCloseEvent close_event;
    OnClose(close_event);
}

wxFrame* NewSettingsFrame() {
    return (wxFrame*)(new SettingsFrame(NULL));
}

<|endoftext|>


<commit_before>#include "ShaderProgram.h"

eyesore::ShaderProgram::ShaderProgram()
{
	id = glCreateProgram();
	id = 0;
}

eyesore::ShaderProgram::~ShaderProgram()
{
	glDeleteProgram(id);
}

void eyesore::ShaderProgram::attach(GLuint shader)
{
	glAttachShader(id, shader);
}

void eyesore::ShaderProgram::use() const
{
	glUseProgram(id);
}

<commit_msg>Add ShaderProgram linking<commit_after>#include "ShaderProgram.h"

eyesore::ShaderProgram::ShaderProgram()
{
	id = glCreateProgram();
}

eyesore::ShaderProgram::~ShaderProgram()
{
	glDeleteProgram(id);
}

void eyesore::ShaderProgram::attach(GLuint shader)
{
	glAttachShader(id, shader);
}

void eyesore::ShaderProgram::use() const
{
	glLinkProgram(id);
	glUseProgram(id);
}

<|endoftext|>